I need help with ode45 function, how to write the code?
4 views (last 30 days)
Show older comments
I need to write a code to solve the differential equatian but I don't even know how to start, I need to use the ode solver to find the solution
This is the hint they gave to me:
And this is the problem:
I already have all the values on the right side in the form of a vector nx1, only scalar numbers are Cf,Cr,m,la,I and lb.
6 Comments
Answers (1)
Sam Chak
on 24 Jan 2024
Hi @Zlatan
It's great that you figured it out. Anyway, here is the code snippet for the state-space version. I would suggest placing certain parameters inside the vehicle ODE function as constants since they remain unchanged for the vehicle. If you need to run the simulation multiple times to analyze the vehicle's responses to the steering angle δ, you will need to pass this parameter (delta) in the vehicle ODE function as shown below:
%% State-space model of your Vehicle
function dxdt = myVehicleODE(t, x, delta)
% parameters (properties that do not change in the vehicle)
Cf = 1;
Cr = 1;
la = 1;
lb = 1;
m = 1;
I = 1;
u = 1;
% Elements in matrices (that depend on the parameters)
a11 = 1;
a12 = 1;
a21 = 1;
a22 = 1;
b1 = 1;
b2 = 1;
% matrices
A = [a11, a12; % state matrix
a21, a22];
B = [b1; % input matrix
b2];
% matrix differential equation (x is the state vector for [v; r])
dxdt = A*x + B*delta;
end
0 Comments
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!