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 comentarios

Image Analyst
Image Analyst el 20 de Abr. de 2016
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.
MRT gang
MRT gang el 21 de Abr. de 2016
Question is updated ! thank you .

Iniciar sesión para comentar.

 Respuesta aceptada

Star Strider
Star Strider el 20 de Abr. de 2016

0 votos

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 comentarios

MRT gang
MRT gang el 21 de Abr. de 2016
Editada: MRT gang el 21 de Abr. de 2016
Really appreciate your help . Any idea about the second half of what i wanted ? thanks
Star Strider
Star Strider el 21 de Abr. de 2016
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.
MRT gang
MRT gang el 29 de Abr. de 2016
thank you very much ! i appreciate your help
Star Strider
Star Strider el 29 de Abr. de 2016
My pleasure!

Iniciar sesión para comentar.

Más respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 20 de Abr. de 2016

0 votos

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

1 comentario

MRT gang
MRT gang el 20 de Abr. de 2016
the result is not the same when using my method ( plot->basic fitting>numerical estimation )

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 20 de Abr. de 2016

Comentada:

el 29 de Abr. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by