Thread: ode45 Matlab
View Single Post
  #6  
Old November 29th, 2008, 07:59 AM
CaptainBlack's Avatar
CaptainBlack CaptainBlack is offline
Grand Panjandrum
 
Join Date: Nov 2005
Location: South of England
Posts: 11,379
Country:
Thanks: 667
Thanked 3,619 Times in 2,916 Posts
CaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond repute
Default

Quote:
Originally Posted by Rapha View Post
Hello CaptainBlack!

Thank you so much for your helpful comment!



I tried it but it still doesn't work.

Code:
function dx = ivp(t, x)
 
dx =  \dot{x} * x;
clearly represented, I wrote \dot{x} for
\dot{\bold{x}}=\left[ \begin{array}{c}
\bold{x}_3\\
\bold{x}_4\\ 
\bold{x}_1-2\bold{x}_4-0.9(\bold{x}_1+0.1)/D_1-0.1(\bold{x}_1-0.9)/D_2 \\ 
\bold{x}_2-2\bold{x}_3-0.9\bold{x}_2/D_1-0.1\bold{x}_2/D_2 
\end{array} \right]

then:

[t, x] = ode45(@ivp, [0, 10], [??,??,??,??] )

where t \in [0, 10] and ?? = [x_3(0); x_4(0);, ...(0); ...(0)]

this is stupid, but I don't know the initial values :-(

Somewere in the staement of the problem there should be initial values.

But you can try any initial values to test the code [0;0;1;1] should do.

the following seems to work on FreeMat:

Code:
function dx=deriv(t,x)
   d1=sqrt(((x(1)+0.1)^2+x(2)^2)^3);
   d2=sqrt(((x(1)-0.9)^2+x(2)^2)^3);
   dx=zeros(4,1);
   dx(1)=x(3);
   dx(2)=x(4);
   dx(3)=x(1)-2*x(4)-0.9*(x(1)+0.1)/d1-0.1*(x(1)-0.9)/d2;
   dx(4)=x(2)-2*x(3)-0.9*x(2)/d1-0.1*x(2)/d2;
with calling statement:

Code:
[t,x]=ode45(@deriv ,[0,10],[0;0;1;1]);
(note the absurdty that we have state and derivative as colum vectors, but the output is an array of row vectors, one for each time point, but it does not work if we have row vectors for the state and derivative!!)

CB
__________________
Truth does not change because it is, or is not, believed by a majority of the people.

Giordano Bruno

Last edited by CaptainBlack; November 29th, 2008 at 08:31 AM.
Reply With Quote
The following users thank CaptainBlack for this useful post:
Donate to MHF