spline interpolation error , index in line 1

2 ビュー (過去 30 日間)
Karolina Nowobilska
Karolina Nowobilska 2021 年 2 月 27 日
コメント済み: Walter Roberson 2021 年 2 月 27 日
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!

採用された回答

Walter Roberson
Walter Roberson 2021 年 2 月 27 日
spline = spline(t,e_t);
After that line spline refers to an array not the function. Use a different variable name.
  2 件のコメント
Karolina Nowobilska
Karolina Nowobilska 2021 年 2 月 27 日
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 2021 年 2 月 27 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by