Taylor series method for 2 coupled ODEs and I'm confused!!!

6 次查看(过去 30 天)
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

采纳的回答

Youssef  Khmou
Youssef Khmou 2013-12-3
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 个评论
Youssef  Khmou
Youssef Khmou 2013-12-3
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?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by