Using ode45 and fzero to solve non-linear second order ODE with 1 unknown.

7 次查看(过去 30 天)
I have a 2nd order non-linear equation that represents the motion of a bobsled down a track.
dx^2/dt^2+K3(dx/dt)^2+K4=0 where K3=3.3465*10^-4 and K4=mu*gamma*z-gsin(alpha)
mu=0.01, gamma*z=15.2, and g=32.2
I have resolved the non linear second order ODE to system of two first order ODE's
dx/dt=v & dv/dt=-K3v^2-K4
The race is measured by time stamps and velocities over an interval,this information is given to solve the problem but to save space I will just provide the size of the matrices.
The end goal is to find the value of alpha (average angle of the track, which is constant over each interval, just varies from interval to interval) the matrices are of size 79x2 where the 79 rows are data for each racer (each racer has 4 times for 4 rows) and 2 columns are start and finish of the given interval.
There is 3 time matrices (T (T1,T2,T3)) and 3 velocity matrices (V (V1,V2,V3)), one for each interval.
I would like to use ode 45 and fzero to generate the values of K4 over an interval and then narrow down to one K4 for each interval. The three K4 values for each interval could then be used to solve for alpha for each interval. I am also trying to use another ode45 function to generate x values for position at each time that correspond to each velocity and make a time series plot of position vs time for only 1 racer. I know that my code is not complete yet but I have provided below what I have generated so far for each ode 45 function and the fzero function for the first interval. I am new to matlab and am a bit lost on syntax for how to do what I want to do.
global az
global T1
global V1
%%az is row and bz is column
az=1
bz=1
k4=@(alpha)(mu.*gammaz)-(g.*sind(alpha));
for az=1:79
[t,v]=ode45(@projectprob,[T1(az,1) T1(az,2)],[V1(az,1) fzero(@res,T1(az,2))]);
alpha(az)=v(1,2)
end
function dvdt=projectprob(t,v)
global az
global T1
global V1
k4=@(alpha)(mu.*gammaz)-(g.*sind(alpha))
%%v(1)=v & v(2)=k4
dvdt = [-k3*v(1).^2-v(2);0];
end
function riz=res(alphaT1)
global az
global T1
global V1
[x,v]=ode45(@projectprob,[T1(az,1) T1(az,2)],[V1(az,1) alphaT1]);
riz=v(length(x),1)-V1(az,2)
end
%%dx/dt=v
%%dv/dt=-k3v^2-k4

回答(1 个)

Walter Roberson
Walter Roberson 2023-5-7
Global variables T1 and V1 were never initialized, so they will be empty when the code is executed. That will cause problems in multiple places in your code.
To solve this... do not use global variables.

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by