Filter löschen
Filter löschen

creating Lagrange interpolation w.r.t. two arrays

3 Ansichten (letzte 30 Tage)
sermet
sermet am 25 Dez. 2017
Bearbeitet: sermet am 26 Dez. 2017
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?

Antworten (1)

ANKUR KUMAR
ANKUR KUMAR am 25 Dez. 2017
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 Kommentare
ANKUR KUMAR
ANKUR KUMAR am 26 Dez. 2017
Is your problem resolved?
sermet
sermet am 26 Dez. 2017
Bearbeitet: sermet am 26 Dez. 2017
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by