Taylor series method for 2 coupled ODEs and I'm confused!!!
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jesse
el 3 de Dic. de 2013
Comentada: Jesse
el 4 de Dic. de 2013
Greetings all,
I'm trying to solve the following initial value problem using the Taylor series method:
x1prime = sin(x1)+cos(t*x2)
x2prime = sin(t*x1)/t
with x1(-1) = 2.37 and x2(-1) = -3.48. I've included the derivates to the third order (see code below), and I'm trying to get it to run until t = 1, and where my step size h = 1.
I didn't include a print statement just yet as I am seeing if I am on the right track. All of the examples I see are for one equation ODE with initial condition, not two, so this is very new to me and I'm quite confused.
Any suggestions would be appreciated.
Code:
function taylor
h = 0.01;
x1 = 2.37;
x2 = -3.48;
t = -1;
for i=1:100
x1prime = sin(x1) + cos (t*x2);
x2prime = sin(t*x1)/t;
x1_2 = cos(x1)-t*sin(t*x2);
x1_3 = -t^2*cos(t*x2)-sin(x1);
x2_2 = cos(t*x1);
x2_3 = -t*sin(t*x1);
x1out = x1+h*(x1prime+0.5*h*(x1_2+(1/3)*h*(x1_3)));
x2out = x2+h*(x2prime+0.5*h*(x2_2+(1/3)*h*(x2_3)));
t = t+h;
end
0 comentarios
Respuesta aceptada
Youssef Khmou
el 3 de Dic. de 2013
Jesse, i think you should add the index to the two solutions, try :
h = 0.01;
x1 = 2.37;
x2 = -3.48;
t = -1;
for i=1:200
x1prime = sin(x1) + cos (t*x2);
x2prime = sin(t*x1)/t;
x1_2 = cos(x1)-t*sin(t*x2);
x1_3 = -t^2*cos(t*x2)-sin(x1);
x2_2 = cos(t*x1);
x2_3 = -t*sin(t*x1);
x1out(i) = x1+h*(x1prime+0.5*h*(x1_2+(1/3)*h*(x1_3)));
x2out(i) = x2+h*(x2prime+0.5*h*(x2_2+(1/3)*h*(x2_3)));
t = t+h;
end
N=length(x1out);
time=linspace(-1,t,N);
plot(times,x1out)
figure,plot(time,x2out,'r'),
3 comentarios
Youssef Khmou
el 3 de Dic. de 2013
hi Jesse, yes, however we need see the history of that chain, in the first code we lost old events X(t-n....), because after each iteration t changes hence all Xs change. what do you think?
Más respuestas (0)
Ver también
Categorías
Más información sobre Ordinary Differential Equations 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!