creating Lagrange interpolation w.r.t. two arrays

1 次查看(过去 30 天)
time=[t1 t2 t3];
data=[y1 y2 y3];
specific_time=tt;
% for specific time tt, computation of data as follows;
data(tt)=((tt-t2)*(tt-t3))/((t1-t2)*(t1-t3))*y1 + ((tt-t1)*(tt-t3))/((t2-t1)*(t2-t3))*y2 + ((tt-t1)*(tt-t2))/((t3-t1)*(t3-t2))*y3
How can I create data(tt) w.r.t. arbitrary number of time and data array?

回答(1 个)

ANKUR KUMAR
ANKUR KUMAR 2017-12-25
time=[t1 t2 t3];
data=[y1 y2 y3];
tt=[tt1 tt2 tt3 tt4 tt5 tt6 tt7];
for i=1:length(tt)
data(i)=((tt(i)-t2)*(tt(i)-t3))/((t1-t2)*(t1-t3))*y1 +...
((tt(i)-t1)*(tt(i)-t3))/((t2-t1)*(t2-t3))*y2 + ((tt(i)-t1)*(tt(i)-t2))/((t3-t1)*(t3-t2))*y3;
end
You can even replace t1 by time(1) and so on.
  3 个评论
sermet
sermet 2017-12-26
编辑:sermet 2017-12-26
No. Your codes are just working for above example. When t and y vectors' length are taken into consideration (they are variable, i.e, changes w.r.t. example), they should be represented as t(i), y(i) within loop.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by