creating Lagrange interpolation w.r.t. two arrays

3 visualizaciones (últimos 30 días)
sermet
sermet el 25 de Dic. de 2017
Editada: sermet el 26 de Dic. de 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?

Respuestas (1)

ANKUR KUMAR
ANKUR KUMAR el 25 de Dic. de 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 comentarios
ANKUR KUMAR
ANKUR KUMAR el 26 de Dic. de 2017
Is your problem resolved?
sermet
sermet el 26 de Dic. de 2017
Editada: sermet el 26 de Dic. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by