Predicting the value at y(t=8) using my model
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Sam Chak
2023-5-29
编辑:Sam Chak
2023-5-29
@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?
回答(2 个)
Sam Chak
2023-5-30
Hi @Matt Boyles
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')
plot(f, x2, y2), grid on
actual_t8 = sin(4*pi/10*8) + sin(6*pi/10*8)
estim_t8 = f(8)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Adaptive Control 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!