Solving a System of Non-linear ODEs on Matlab
University course discussion for mathematics. Use the Maths Study Help forum for help with maths questions.
| Announcements | Posted on | |
|---|---|---|
| Important: please read these guidelines before posting about exams on The Student Room | 28-04-2013 | |
-
Solving a System of Non-linear ODEs on Matlab
I have a system of two non-linear ODEs which I am trying to solve numerically using Matlab. I have never used Matlab for this sort of thing, so I thought I'd work through a demo that they give in the Help files. These are the two pieces of code I'm using:
function [ dy ] = rigidtest( t,y )
y = zeros(3,1); % a column vector
dy(1,1) = y(2) * y(3);
dy(2,1) = -y(1) * y(3);
dy(3,1) = -0.51 * y(1) * y(2);
endNow according to the Matlab demo I should get some nice sine-curve-looking graphs. But I get three straight lines, with no deviation from the initial conditions. Also, my [T,Y] vector is only 41 lines long!options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4 1e-5]);
[T,Y] = ode45(@rigidtest,[0 12],[0 1 1],options);
plot(T,Y(:,1),'-',T,Y(:,2),'-.',T,Y(:,3),'.')
Any idea what I'm doing wrong?
Thanks
Jez