creating Lagrange interpolation w.r.t. two arrays

3 ビュー (過去 30 日間)
sermet
sermet 2017 年 12 月 25 日
編集済み: sermet 2017 年 12 月 26 日
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 件のコメント
ANKUR KUMAR
ANKUR KUMAR 2017 年 12 月 26 日
Is your problem resolved?
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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by