spline interpolation error , index in line 1

2 visualizaciones (últimos 30 días)
Karolina Nowobilska
Karolina Nowobilska el 27 de Feb. de 2021
Comentada: Walter Roberson el 27 de Feb. de 2021
c0 = 47000000 ;
e0 = 6110000 ;
dt = 0.5 ;
tmax = 5;
t = 0:dt:tmax ;
gamma = 0.08;
u = 0.05;
v = 0.05;
e = 0.02;
a = 1;
b = 1;
a1 = 4;
b1 = 9;
phi = gamma+u+v+e;
xi = u + v;
e_t = e0 + b.*t - 0.5.*(xi.*a-e.*b).*t.^2;
e_t_1 = e0 + b1.*t - 0.5.*(xi.*a1-e.*b1).*t.^2;
spline = spline(t,e_t);
spline1 = spline(t,e_t_1);
plot(t, spline)
hold on
plot(t,e_t_1)
hi i'm fairly new on matlab and would like to interpolate my results to get an accurate graph. Im getting an error which says " Index in position 1 is invalid. Array indices must be positive integers or logical values. Error in line 28 spline = spline(t,e_t); ". Would you be able to help me solve this issue? Also would it be more beneficial to use lagrange interpolation or spline? Thanks!

Respuesta aceptada

Walter Roberson
Walter Roberson el 27 de Feb. de 2021
spline = spline(t,e_t);
After that line spline refers to an array not the function. Use a different variable name.
  2 comentarios
Karolina Nowobilska
Karolina Nowobilska el 27 de Feb. de 2021
Thank you, once I did that It was able to work, however I got another error saying "Error using plot There is no form property on the Line class."
So I changed the code to say:
plot(t, k,'r')
to which I got another error saying "Invalid data argument."
Is there anyway you can also help me with that?
Walter Roberson
Walter Roberson el 27 de Feb. de 2021
variable = spline(t,e_t);
That form of spline() returns a piecewise polynomial. In order to plot it, you need to use ppval() indicating the places you wish to plot at.
In your case you could probably use
variable = spline(t,e_t, t);
which will return the interpolated values.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by