Taylor series method for 2 coupled ODEs and I'm confused!!!
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!