I have two arrays:
1_time ->
t=(0:15);
2_measurements ->
data1=[ 0 7 20 28 35 48 57 61 72 82 96 98 111 121 129 144 ];
I have to get the estimation at t=20 ( linear method ) ,and the 'minimum & maximum' difference between the linear equation line and the data1 curve .
My method was :
1 Making a plot ->
plot(t,data1);
2 Getting the estimated at t=20 by using the numerical panel (tool-> basic fitting)
3 And finally i get the 'minimum & maximum' difference between the linear equation line and the data1 curve , by plotting the residuals
Is there any code to get what i want and not by using plotting .. ect ? I am a newbie when it come to matlab

2 个评论

This is a 1-D curve, not a 2-D curve. For each element of your dependent variable, "data1", there is exactly one independent variable, "t", that specifies it, not two. data1 is a 1-D vector, not a 2-D matrix.
Question is updated ! thank you .

请先登录,再进行评论。

 采纳的回答

If you are confident of a linear fit, just calculate the extrapolated ‘data1’ value at ‘t=20’:
t=(0:15);
data1=[ 0 7 20 28 35 48 57 61 72 82 96 98 111 121 129 144 ];
B = [t' ones(size(t'))]\data1'; % Estimate Coefficient Of Linear Fit
data1_fit = [t' ones(size(t'))]*B; % Create Regression Line To Plot
data1_20 = [20 1]*B % Extrapolate Fit To ‘t=20’
figure(1)
plot(t, data1, 'bp')
hold on
plot(t, data1_fit, '-g')
plot(20, data1_20, '*r')
hold off
grid
axis([0 21 -10 200])
This code plots the data and fit using the mldivide,\ operator, and plots and calculates the extrapolated value:
data1_20 =
186.43

4 个评论

MRT gang
MRT gang 2016-4-21
编辑:MRT gang 2016-4-21
Really appreciate your help . Any idea about the second half of what i wanted ? thanks
My pleasure.
I believe I did both. The plot is figure(1), and the extrapolation is this line:
data1_20 = [20 1]*B % Extrapolate Fit To ‘t=20’
producing:
data1_20 =
186.43
I didn’t see part 3. about the residuals and residual plot until I went looking for it just now. Add this to the end of my previous code, and I believe we’ve covered everything:
resid = data1 - data1_fit';
resid_extr = [min(resid) max(resid); min(abs(resid)) max(abs(resid))];
logc_vct = [abs(resid) == resid_extr(2,1); abs(resid) == resid_extr(2,2)];
figure(2)
stem(t, resid)
hold on
plot(t(logc_vct(1,:)), abs(resid(logc_vct(1,:))), '*r', t(logc_vct(2,:)), abs(resid(logc_vct(2,:))), '*r')
hold off
grid
xlabel('Time')
ylabel('Residual')
axis([-1 16 ylim])
The ‘resid_extr’ matrix are the minima and maxima of the residuals and the absolute values of the residuals. I plotted all and highlighted the minimum and maximum absolute values. I used logical vectors rather than the find function in the ‘logc_vct’ array, just for variety. It doesn’t make any difference in the behaviour of the code.
thank you very much ! i appreciate your help
My pleasure!

请先登录,再进行评论。

更多回答(1 个)

out=interp1(t,data1,20,'linear','extrap')

1 个评论

the result is not the same when using my method ( plot->basic fitting>numerical estimation )

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by