Predicting the value at y(t=8) using my model

Hi,
I am completeing some LLS analysis and need to predict the value of my model after 8 seconds.
% Problem 3
clc
close all
% Load Data
t = LLS_Data3(:,1);
y = LLS_Data3(:,2);
% Plot the data
figure;
plot(t,y,'.')
% Apply LLS
AL = [t,ones(size(x))]; %
thetaL = inv(AL.'*AL)*(AL.')*y;
yML = thetaL(1)*t + thetaL(2); % Based on equation
% Plot Error over time
figure(1)
errorL = y - yML;
plot(t,errorL, 'x')
xlabel('Time')
ylabel('Error')
hold on
yline(0, 'k')
hold off
This is my current code but am unsure how to use the model to predict my Y value (yML) at t = 8 seconds. The given data set runs for 10 seconds and there are currently 7 values given throughout the 10 second period.
Any help would be appreciated,
Thank you

2 Comments

Sam Chak
Sam Chak on 29 May 2023
Edited: Sam Chak on 29 May 2023
@Matt Boyles: The given data set runs for 10 seconds and there are currently 7 values given throughout the 10 second period.
Are you suggesting that there are only 7 data points over the entire 10-second period?
Are you looking to predict the output at exactly t = 8 seconds using the LLS model?
Yes exactly, thanks

Sign in to comment.

Answers (2)

Torsten
Torsten on 29 May 2023
Moved: Torsten on 29 May 2023
thetaL(1)*8 + thetaL(2)

2 Comments

Thankyou,
What about for a more complex equation like
yM7 = theta7(1)*t.^7 + theta7(2)*t.^6 + theta7(3)*t.^5 + theta7(4)*t.^4 + theta7(5)*t.^3 + theta7(6)*t.^2 + theta7(7)*t + theta7(8); %
Is it the same premis that I would just multiply each t value by 8? it doesnt seem correct to me.
Thanks for your help!!
If you have a function yM7(t) and you want to find its value at t=8, how do you do that ? You insert 8 for t, don't you ?

Sign in to comment.

You can try something like the following to estimate the output. However, there is no guarantee that the estimation at sec is accurate, as shown in the following example.
subplot(2, 1, 1)
nPts1 = 1001; % number of points
x1 = linspace(0, 10, nPts1);
y1 = sin(4*pi/10*x1) + sin(6*pi/10*x1);
plot(x1, y1, 'linewidth', 1.5), grid on
xlabel('x')
subplot(2, 1, 2)
nPts2 = 7; % number of points
x2 = linspace(0, 10, nPts2);
y2 = sin(4*pi/10*x2) + sin(6*pi/10*x2);
% plot(x2, y2, 'rp')
xlabel('x')
f = fit(x2', y2', 'poly6')
f =
Linear model Poly6: f(x) = p1*x^6 + p2*x^5 + p3*x^4 + p4*x^3 + p5*x^2 + p6*x + p7 Coefficients: p1 = -5.586e-17 p2 = 0.005051 p3 = -0.1263 p4 = 1.099 p5 = -3.858 p6 = 4.443 p7 = 2.993e-13
plot(f, x2, y2), grid on
actual_t8 = sin(4*pi/10*8) + sin(6*pi/10*8)
actual_t8 = 7.7716e-16
estim_t8 = f(8)
estim_t8 = -0.3861

Categories

Find more on Programming in Help Center and File Exchange

Asked:

on 29 May 2023

Commented:

on 31 May 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!