MATLAB Answers

spline interpolation error , index in line 1

22 views (last 30 days)
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!

Accepted Answer

Walter Roberson
Walter Roberson on 27 Feb 2021
spline = spline(t,e_t);
After that line spline refers to an array not the function. Use a different variable name.
  2 Comments
Walter Roberson
Walter Roberson on 27 Feb 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.

Sign in to comment.

More Answers (0)

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by