| 
November 26th, 2008, 09:41 PM
| | Senior Member | | Join Date: Nov 2008
Posts: 424
Thanks: 62
Thanked 157 Times in 150 Posts
| | ode45 Matlab Hello everyone!
I need to solve a IVP, for example
x(0) = 0.995
y(0) = 0
(I actually don't know if there is a solution...)
But how to solve it by using ode45?  depends on  and y ...
By the way,
I know how to solve
v0 = v(0) = 0
for example:
[ t , v ] = ode45 (@( t , v ) 10-5v^2/2 , [0, 10], v0 ) ;
----
How to solve the IVP with 2 equations?
Best regards,
Rapha | 
November 26th, 2008, 10:07 PM
|  | Grand Panjandrum | | Join Date: Nov 2005 Location: South of England
Posts: 12,285
Country: Thanks: 779
Thanked 4,005 Times in 3,230 Posts
| | Quote:
Originally Posted by Rapha Hello everyone!
I need to solve a IVP, for example
x(0) = 0.995
y(0) = 0
(I actually don't know if there is a solution...)
But how to solve it by using ode45?  depends on  and y ...
By the way,
I know how to solve
v0 = v(0) = 0
for example:
[ t , v ] = ode45 (@( t , v ) 10-5v^2/2 , [0, 10], v0 ) ;
----
How to solve the IVP with 2 equations?
Best regards,
Rapha | Eliminate the  term in the first equation by substituting from the second, and  for the second by substituting from the first:
So now writing this as a first order vector ODE:
where:
So now can you get ode45 to work?
CB
__________________ Truth does not change because it is, or is not, believed by a majority of the people.
Giordano Bruno | | The following users thank CaptainBlack for this useful post: | |  | 
November 27th, 2008, 07:42 AM
| | Senior Member | | Join Date: Nov 2008
Posts: 424
Thanks: 62
Thanked 157 Times in 150 Posts
| | Hello. Quote: |
So now can you get ode45 to work?
| that was very helpful, thank you very much (and yes, i could get ode45 to work).
But actually i kinda screwed it(sorry, i did not exactly realize what my problem was and asked for something different), because my problem is :
with
i tried to find the IVP 1. order:
=>
I did not realize that there are 4 functions:
I still want to solve this by using ode45.
Regards
Rapha
Last edited by Rapha; November 27th, 2008 at 08:12 AM.
| 
November 27th, 2008, 09:58 PM
|  | Grand Panjandrum | | Join Date: Nov 2005 Location: South of England
Posts: 12,285
Country: Thanks: 779
Thanked 4,005 Times in 3,230 Posts
| | Quote:
Originally Posted by Rapha Hello.
that was very helpful, thank you very much (and yes, i could get ode45 to work).
But actually i kinda screwed it(sorry, i did not exactly realize what my problem was and asked for something different), because my problem is :
with
i tried to find the IVP 1. order:
=>
I did not realize that there are 4 functions:
I still want to solve this by using ode45.
Regards
Rapha | Now we have as state vector:
and derivative:
where:
You will need to write a Matlab function to evaluate the derivative and pass that to ode45 (the derivative is now too complicated to be easily passed as an anonymous function).
(You cound simplify the derivative by collecting terms)
CB
__________________ Truth does not change because it is, or is not, believed by a majority of the people.
Giordano Bruno | | The following users thank CaptainBlack for this useful post: | |  | 
November 29th, 2008, 04:35 AM
| | Senior Member | | Join Date: Nov 2008
Posts: 424
Thanks: 62
Thanked 157 Times in 150 Posts
| | Hello CaptainBlack!
Thank you so much for your helpful comment! Quote:
Originally Posted by CaptainBlack You will need to write a Matlab function to evaluate the derivative and pass that to ode45 (the derivative is now too complicated to be easily passed as an anonymous function).
(You cound simplify the derivative by collecting terms) | I tried it but it still doesn't work. Code: function dx = ivp(t, x)
dx = \dot{x} * x;
clearly represented, I wrote  for
then:
[t, x] = ode45(@ivp, [0, 10], [??,??,??,??] )
where ![t \in [0, 10] t \in [0, 10]](http://www.mathhelpforum.com/math-help/latex2/img/1c75f0e0c25ae64c5fe7e65227bbcb32-1.gif) and ?? = [x_3(0); x_4(0);, ...(0); ...(0)]
this is stupid, but I don't know the initial values :-( | 
November 29th, 2008, 06:59 AM
|  | Grand Panjandrum | | Join Date: Nov 2005 Location: South of England
Posts: 12,285
Country: Thanks: 779
Thanked 4,005 Times in 3,230 Posts
| | Quote:
Originally Posted by Rapha 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  for
then:
[t, x] = ode45(@ivp, [0, 10], [??,??,??,??] )
where ![t \in [0, 10] t \in [0, 10]](http://www.mathhelpforum.com/math-help/latex2/img/1c75f0e0c25ae64c5fe7e65227bbcb32-1.gif) 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 07:31 AM.
| | The following users thank CaptainBlack for this useful post: | |  | 
November 29th, 2008, 09:21 PM
| | Senior Member | | Join Date: Nov 2008
Posts: 424
Thanks: 62
Thanked 157 Times in 150 Posts
| | Quote:
Originally Posted by CaptainBlack Somewere in the staement of the problem there should be initial values. | Oooops
I forgot to post them :-( Quote:
Originally Posted by CaptainBlack 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: | Alright, thank you. You are great!
Rapha
Last edited by Rapha; November 29th, 2008 at 09:44 PM.
| | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | All times are GMT -7. The time now is 04:31 PM. | | |