Calculate displacement of a mdof sytem with ODE45?
이전 댓글 표시
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.
채택된 답변
추가 답변 (3개)
Bas
2012년 9월 6일
편집: Sean de Wolski
2012년 9월 6일
댓글 수: 3
Bas
2012년 9월 6일
Matt Tearle
2012년 9월 6일
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
2012년 9월 6일
Bas
2012년 9월 7일
댓글 수: 5
Matt Tearle
2012년 9월 7일
Don't worry about the intermediate error messages. That's just the full trace from your initial script to the final error. The error is, of course, happening when you call ode45, so you're seeing an error in a function inside a function inside a function...
The problem is what you've identified: K is 4-by-4 and y is 8-by-1. Note in my original answer I said K and M would have to be 8-by-8 because you need to write the equations as My' = -Ky where y is the 8-element vector [x1; x1dot; phi ...]
That means that y' = [x1dot; x1dotdot; phidot; phidotdot; ...] = [y2; 50*x1 + 5*phi + x2 + x3; ...] = [y2; 50*y1 + 5*y3 + y5 + y7;...]. So K should be something like
[0 1 0 0 0 0 0 0]
[50 0 5 0 1 0 1 0]
[0 0 0 1 0 0 0 0]
[5 0 50 0 1 0 1 0]
[0 0 0 0 0 1 0 0]
[1 0 1 0 25 0 0 0]
[0 0 0 0 0 0 0 1]
[1 0 1 0 0 0 25 0]
(I think, based on what you have for K currently). And similarly for M.
Bas
2012년 9월 10일
Matt Tearle
2012년 9월 12일
Inside odefun you have t and y, so you can calculate anything based on those values at the current timestep. It looks like phi is y_2, so
K = [50*cos(y(2)) 5 1 1;...]
Also, don't use inv(M). Use the Mass option in ode45. But if you really don't want to do that, at least use -M\(K*y(5:8)) instead of inv(M).
I also think you may have your indices for y back-to-front somewhere. In the calling script, it seems like y_2 is phi and y_6 is phi'. If that's the case, then, in odefun, dydt(2) would be phi', so dydt(2) = y(6). And dydt(8) would be phi'' (calculated from M\K*y). In other words, in the script, y(1:4) are the primitive variables and y(5:8) are the derivatives; but in the function it's the other way around.
Bas
2012년 9월 17일
Matt Tearle
2012년 9월 18일
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.)
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!