How to solve ODE
Show older comments
Hello,
I have following nonlinear ODE-System: G(x)*x'=0
How can I solve this ODE-System with respect to x'=f(x)
so I need f(x)...
Thank you!
4 Comments
Star Strider
on 28 Jul 2012
You have a homogeneous differential equation. These are not ususual. What is ‘G(x)’ and what are the initial conditions?
John Miller
on 28 Jul 2012
Edited: John Miller
on 28 Jul 2012
Star Strider
on 29 Jul 2012
Edited: Star Strider
on 29 Jul 2012
The ODE solvers don't have to have a square matrix argument, but the matrix argument does have to have as many rows as it has orders of derivatives, so that it is set up as a system of first-order ODEs. So if it's a second-degree ODE it has to have two rows, third-degree, three, etc. It definitely doesn't have to be square. For instance, the spring-mass-damper system:
mx" = u - k*x' - k2*x, where: x' = dx/dt, x" = d^2x/(dt^2)
is defined for ode45 as:
xdot(1) = x(2);
xdot(2) = -x(1)*k(2)/m -x(2)*k(1)/m + u(t)/m;
and works fine. I don't know if the Symbolic Math Toolbox can format your equations for you (you can ask it and find out), but I suggest it because it avoids algebra errors. If not, you can do it with pencil and paper.
John Miller
on 29 Jul 2012
Answers (1)
Star Strider
on 29 Jul 2012
Edited: Star Strider
on 29 Jul 2012
I asked the Symbolic Math Toolbox and it suggested that I refer you to the odeToVectorField function: http://www.mathworks.com/help/toolbox/symbolic/odetovectorfield.html.
When I gave it this code for the ODE I listed above:
syms m x(t) u k1 k2
% Differential Equation: mx" = u - k1*x' - k2*x
[V,Y] = odeToVectorField(m*diff(x,2) == u - k1*diff(x,1) - k2*x)
it returned:
V =
Y[2]
-(k1*Y[2] - u + k2*Y[1])/m
Y =
x
Dx
The ‘V’ output is the argument you will give to your ODE function, and the ‘Y’ ouput are the substitutions it made. It assumes you know that on the left side of ‘V’ to put the vector:
Ydot(1)
Ydot(2)
if necessary, depending on how your format the equation you use as one of your ODE arguments. You don't have to, though. You can just give it the matrix. The ODE functions assume the rest.
4 Comments
John Miller
on 29 Jul 2012
Edited: John Miller
on 29 Jul 2012
Star Strider
on 29 Jul 2012
Your matrix is not a set of differential equations the ODE solvers can deal with. Neither they nor I can figure out what you want to do.
You have a [2 x 3] matrix in nonlinear functions of [y(1), y(2), y(3)] if I visually parsed it correctly, but I cannot figure out where the y-vector came from or what it represents. Did your matrix start out as a third-degree differential equation?
I believe you need to go back to the Symbolic Math Toolbox with your original differential equation, then use ‘odeToVectorField’ as I did in my example to get a differential equation that will work with the ODE solvers.
If you are still having problems with it after that, post what you have already done here along with a description of the errors you got or the problems you had, and we will be glad to help you.
John Miller
on 30 Jul 2012
Edited: John Miller
on 30 Jul 2012
Star Strider
on 30 Jul 2012
The fundamental problem is that because your ‘M’ matrix is [2 x 3] and you have three unknowns, you have an under-determined system. There is no unique solution. That is the reason I suggested that you go back to the Symbolic Math Toolbox and start over.
I suggest that to you again.
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!