How do i transform a second grade ODE into coordinates?

5 visualizaciones (últimos 30 días)
Nicolae Lungu
Nicolae Lungu el 18 de En. de 2021
Editada: James Tursa el 22 de En. de 2021
Hello,
I'm new to matlab and i'm quite struggling with it.
I have been assigned a coursework in which i must find the trajectory of a projectile.Within it there is a second order ODE which i must transform into x&y's in order to get a system of first-order equations.
The second order equation is: r''(t) = (1 /m)* (((− 1 /2 )*ρ*cd*A*|r'|*r' )− mg );
Mathematically, this system will be expressed a:
y' = F(t, y(t))=dy/dt,
where: y(t) = [vx(t), vy(t), rx(t), ry(t)]
Is there any way to accomplish that in matlab and could anyone give suggestions with examples on how to do so?
Thanks!

Respuesta aceptada

James Tursa
James Tursa el 19 de En. de 2021
Editada: James Tursa el 19 de En. de 2021
Looks like motion is restricted to be on the x-y plane, so r is 2D. You have a 2nd order ODE in a 2D frame, so that means you have a 2 * 2 = 4th order system of 1st order equations. Define the following:
r = [x;y]
From that define a state vector consisting of all the variables and derivatives up to but not including the highest order:
Y = [x;y;xdot;ydot]
Then the derivative of your state vector is
Ydot = d/dt [x;y;xdot;ydot] = [xdot;ydot;xdotdot;ydotdot] = [Y(3);Y(4);xdotdot;ydotdot]
So then you simply need to get the expressions for xdotdot and ydotdot. You do this by rewriting your rdotdot equation above in terms of x and y using the definition r = [x;y]. You do that by replacing the following
r' = d/dt r = d/dt [x;y] = [xdot;ydot] = [Y(3);Y(4)]
Thus
|r'| = norm([Y(3);Y(4)])
That being said, you are missing something on the -mg term. This is a vector equation so you need to attach a vector direction for this. I would assume this should be in the y direction (vertical).
So write a derivative function or function handle that takes in a 4-element Y vector and outputs the Ydot vector.
  12 comentarios
Nicolae Lungu
Nicolae Lungu el 22 de En. de 2021
ok now the code looks like this drag_ode:
function Ydot = drag_ode(t, y)
% y is [x coordinate; y coordinate; dx/dt; dy/dt]
m= 0.005; % mass of the projectile
g= 9.81; % acceleration due to gravity constant
cd= 0.479; % Drag coefficient
D= 0.1; % Diametet m
A=pi*(D/2)^2; % Area of sphere, A=0.0314 (m)
rho = 1.225; % density of atmosphere near Earth surface(kg/m^3)
%y = [t;y;tdot;ydot];
% Ydot = [y(3);y(4);tdotdot;ydotdot];
%Ydot = zeros(4,1);
ydot(1) = y(3); % d (x coordinate)/dt = dx/dt
ydot(2) = y(4); % d (y coordinate)/dt = dy/dt
ydot(3) = tdotdot;
ydot(4) = ydotdot;
rdot = [ydot(3);ydot(4)];
rdotdot = (1/m)*(((-1/2)*rho*cd*A*norm(rdot)*rdot)-m*[0;g]);
Ydot = [rdot;rdotdot];
end
and like this for solve_ode45:
function [rx,ry,vx,vy]= solve_ode45(v0,h,dt,theta)
g = 9.81; % acceleration due to gravity at Earth surface(m/s^2)
cD = .479; % coefficient of drag
m = 5.5; % mass(kg)
v0 = 150; % the initial velocity
t(1) = 0; % the initial time
tF = 20; % the end time
dt = 0.001;
theta = 45;
tspan = (0:dt:25);
IC=[0; h; v0*cosd(theta); v0*sind(theta)];% IC-the initial coordinates
[t(1), oput] = ode45(@drag_ode, tspan, IC);
rx = oput(:,1); %Position coordinates for x axis
vx = oput(:,2); %Velocity coordinates for x axis
ry = oput(:,3); %Position coordinates for y axis
vy = oput(:,4); %Velocity coordinates for y axis
figure(1); clf;
plot(x,y);
xlabel('Distance (m) ');
ylabel('Height (m) ');
title('Motion of projectile');
end
and i still get the error:
solve_ode45(150, 5, 25, 45)
Undefined function or variable 'tdotdot'.
Error in drag_ode (line 15)
ydot(3) = tdotdot;
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in solve_ode45 (line 13)
[t(1), oput] = ode45(@drag_ode, tspan, IC);
James Tursa
James Tursa el 22 de En. de 2021
Editada: James Tursa el 22 de En. de 2021
Why do you keep putting code in where I tell you to delete it? Why do you keep using variables such as tdotdot and ydotdot that don't exist?
Delete this code completely:
ydot(1) = y(3); % d (x coordinate)/dt = dx/dt
ydot(2) = y(4); % d (y coordinate)/dt = dy/dt
ydot(3) = tdotdot;
ydot(4) = ydotdot;
and put this line back the way it was:
rdot = [y(3);y(4)];
And then the output is in x,y,xdot,ydot order, so change to this:
rx = oput(:,1); %Position coordinates for x axis
ry = oput(:,2); %Position coordinates for y axis
vx = oput(:,3); %Velocity coordinates for x axis
vy = oput(:,4); %Velocity coordinates for y axis

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by