Calculate displacement of a mdof sytem with ODE45?
3 views (last 30 days)
Show older comments
I am modelling a 2D half-car model in SimMechanics and MapleSim (to compare these two multibody software packages) for my project. My supervisor also want me to make a analytical model for comparing the outputs of both programs. So I have derived the mass matrix and stiffness matrix of this half-car model and I now want to calculate the displacement in vertical direction of the car. My supervisor told me I could do this with ODE45. I do not have any experience with MATLAB, so I have no idea what to do now.
This is my equation:
Mx"+Kx= 0 where M and K are a 4x4 matrix and they change every timestep(they are dependent of angle phi)
I have four generalised coordinates, so I have the initials conditions y0 which is a column of 8 scalars(displacement and velocity at the start)
My supervisor told me something like this: y = [x; xdot] so ydot=[xdot; xddot] where xddot is equal to: inv(M)-Kx, this is clear to me. This only has to be done for all the 4 generalised coordinates. so y = [x1; x1dot; phi; phidot; x2; x2dot; x3; x3dot] and for ydot the same. Am I right?
But what next? What do I have to do in MATLAB to generate the displacement using the ODE45 solver... Maybe I am a bit vague, so if you want to know something, just ask.
0 Comments
Accepted Answer
Matt Tearle
on 6 Sep 2012
You're definitely on the right track. Write your equations in matrix form My' = -Ky where y is the 8-element vector you described. In this setting, M and K will be 8-by-8 matrices (which are functions of t and y).
Then in MATLAB
f = @(t,y) -[matrix K goes here]*y;
m = @(t,y) [matrix M goes here];
[t,y] = ode45(f,...,odeset('Mass',m));
You may also need to set other options related to the mass matrix. See doc odeset for details.
0 Comments
More Answers (3)
Bas
on 6 Sep 2012
Edited: Sean de Wolski
on 6 Sep 2012
3 Comments
Matt Tearle
on 6 Sep 2012
Sorry, I was skipping bits of the code (doc style). Check the documentation for the full syntax for ode45. There should be more stuff (a timespan vector and initial conditions) in place of the "...". MATLAB treats a literal "..." as "this line is incomplete, see the next line for the rest" (and ignores the rest of the line). That's what's causing the error.
Bas
on 7 Sep 2012
5 Comments
Matt Tearle
on 18 Sep 2012
Your supervisor may have been thinking about just getting it working, and using inv is simple, conceptually and practically. Furthermore, in your example, the inverse is probably pretty painless.
But inv is, in general, slow and numerically sensitive. There are almost always better ways to do it, in terms of accuracy and efficiency. If an alternative is offered (such as the Mass property), you can bet that it's better.
(But, again, "better" can be a subjective term. If your goal is just to make this work, the simplest implementation may be the best.)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!