Hello everyone,
I'm pretty new to matlab and writing ODE codes. I just finished my first grader project, and i want to ask a question about ODE writing.
Here is the code that was not work well;
function dYdt = racecarfun(t,Y);
Y1=Y(1);
Y2 = Y(2);
Y3=Y(3);
dY1dt=Y2;
dY2dt=Y3;
F = 4000.0; % force on car, [N]
m = 1300.0; % mass of car, [kg]
A = 3.0; % frontal area, [m^2]
Cd = 0.6; % drag coefficient, [-]
rho = 1.23;
dY3dt=((F-(Cd*rho*A*0.5*Y2.^2))/m);
dYdt=[dY1dt;dY2dt;dY3dt];
end
and here is the code i wrote after a quick search;
function dydt = racecarfun(t,y);
dydt=zeros(2,1);
dydt(1)=y(2);
F = 4000.0; % force on car, [N]
m = 1300.0; % mass of car, [kg]
A = 3.0; % frontal area, [m^2]
Cd = 0.6; % drag coefficient, [-]
rho = 1.23;
dydt(2)=((F-(Cd*rho*A*0.5*y(2).^2))/m);
end
In the first one, i wanted to write all x,v and a in formula however, the example goes with only v and a in the second one. I wonder what is the problem with the first code?

 Respuesta aceptada

Jan
Jan el 28 de Mayo de 2021

1 voto

In your first code, (F-(Cd*rho*A*0.5*Y2.^2))/m is the 3rd derivative of the position. From a physical point of view, this value is surely the acceleration, so it must be the 2nd derivative of the position. Therefore the 2nd code has a physical meaning.

4 comentarios

Rahan Öztürk
Rahan Öztürk el 28 de Mayo de 2021
i am not sure i understand it clearly.
Y1=Y(1); ---> i wanted Y(1) is my x,
Y2 = Y(2);
Y3=Y(3);
dY1dt=Y2; ---> so, dxdt can be v,
dY2dt=Y3 ---> and dvdt is the a
what i am thinking wrong?
Jan
Jan el 28 de Mayo de 2021
Your function dYdt = racecarfun(t,Y) calculate the derivative to the point [t,Y]. The position is not a part of the derivative, but only the velocity and the acceleration. So you are right partially: dY1dt=Y(2) is the velocity, dY2dt=Y(3) is the accleration, but then dY3dt is the "jerk", the 3rd derivative. But you provide a formula according to a = F/m, so this is the acceleration, the 2nd derivative, not the 3rd one.
If you have a equation for the 3rd derivative, your code would work again. But this equation cannot be a force devided by the mass.
Rahan Öztürk
Rahan Öztürk el 30 de Mayo de 2021
So, Y(1) is already first derivative of x. Therefore i need Y(1) for "v" and dY1dt=Y(2) for "a".
Thank your for your time Jan, have a good day.
Torsten
Torsten el 30 de Mayo de 2021
No. Y1 is X, dY1/dt = Y2 is v and dY2/dt is a.

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Etiquetas

Preguntada:

el 28 de Mayo de 2021

Comentada:

el 30 de Mayo de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by