Writing ODE equations for ode45 to solve;

Hi there!
I have a basic question to ask here, regarding writing the first-order equations for ode45 to solve.
Let's say I am solving Newton's 2nd law equations of motion F = ma.
In my function file, the left-hand-side of each equation will be:
  1. vx (velocity of x-component)
  2. vx (velocity of y-component)
  3. omega (angular velocity)
  4. ax (acceleration of x)
  5. ay (acceleration of y)
  6. omegadot (angular acceleration)
For equations 4, 5, 6, I need to use Newton's law ma = F.
Should I write ma = F as is, or do I need to isolate ax, ay, and omegadot, by dividing both sides by the mass m and the moment of inertia I, respectively? My LHS m*a is pretty lengthy, after using the product rule, chain rule, etc., so I wonder if I can just keep it as is, ma = F.
I then create an anonymous function that calls the above function, and this anonymous function is passed into ode45.
Updafe: I just tinkered with this a bit, and it does seem that I can write ma = F as is, but I have to use the double == sign, to equate values from each side, and that the single = sign is for assigning a value to a variable name. Please let me know if you have other thoughts to share.
Thanks!

 Respuesta aceptada

Torsten
Torsten el 30 de Oct. de 2024
Movida: Torsten el 30 de Oct. de 2024

0 votos

The form of the equations that can be solved by ode45 is M*y'(t) = f(t,y). So you can decide whether you choose M to be the identity matrix (that is: whether you isolate ax, ay and omegadot) or not.

6 comentarios

Noob
Noob el 30 de Oct. de 2024
Thanks as always, Torsten! Yes, but I found that I have to use the double equality == in my differential equations within my function file, to equate values, and that the single = sign is for assigning a value to a variable name. Please let me know if you have other thoughts. I'll accept your answer now. Thanks again!
You would use == only with the context of symbolic expressions. For example,
syms F(t) vx(t) vy(t) m
omega = sqrt(vx^2 + vy^2);
ax = diff(vx,t);
ay = diff(vy,t);
omega_dot = sqrt(ax^2 + ay^2);
eqn = F == m * omega_dot;
dsolve(eqn)
Torsten
Torsten el 30 de Oct. de 2024
Editada: Torsten el 30 de Oct. de 2024
Where do you use == ? While specifying your equations in symbolic form to prepare them for use with "ode45" via "odeToVectorField" ?
Noob
Noob el 30 de Oct. de 2024
Oh! Nope, while I do have the Symbolic Math toolbox, I am not using it (I don't know how to use it).
I am using the single = to write ma = F in a function file.
But I am getting a warning message to use the double == sign, for equating two values.
Should I stick with the single = sign?
Noob
Noob el 30 de Oct. de 2024
Hi Torsten / Walter,
I just tried writing ma = F as is, within my function file, but Matlab tells me it's not valid Matlab syntax.
Torsten
Torsten el 30 de Oct. de 2024
Editada: Torsten el 30 de Oct. de 2024
Numerical assignments only use the single "=" sign. I don't know what you try to do in your function file.
If you want to set something like
a11*y1' + a12*y2' + a13+y3' = f1
you will have to set the elements a11, a12 and a13 in the mass matrix M and the expression for f1 in your function of the right-hand side.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Productos

Versión

R2024b

Etiquetas

Preguntada:

el 30 de Oct. de 2024

Editada:

el 30 de Oct. de 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by