ode function 45 how to implement it
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
My code is not working properly, what should i change so i ge the results. I m haveing trouble with ode function and i think with these passing parameters and initial conditions.
clc
maks = xlsread("all_units.xlsx");
a=1.024;
b=1.602;
m=1574.02;
v=maks(:,24);
r=maks(:,20);
u=maks(:,23);
t1=maks(:,25);
cr=-25488;
cf=-184780;
I=1790;
del=(maks(:,18)+maks(:,19))/2;
alfaf= atan((v+r.*a)./u)-del;
alfar= atan((v-r.*b)./u);
Fyf=alfaf*cf;
Fyr=alfar*cr;
% Time span for the simulation
tspan = [min(t1),max(t1)];
% Initial condition
x0 = [0; 0] %for v0 and r0
% Solve the differential equation using ode45
[t, x] = ode45(@(t, x) myVehicleODE(t, x, delta_function(t)), tspan, initial_conditions);
figure;
subplot(2, 1, 1);
plot(t, x(:, 1), 'b', 'LineWidth', 2);
title('Longitudinal Velocity (v)');
subplot(2, 1, 2);
plot(t, x(:, 2), 'r', 'LineWidth', 2);
title('Yaw Rate (r)');
xlabel('Time');
% State-space model of your Vehicle
function dxdt = myVehicleODE(t, x, del)
% Elements in matrices (that depend on the parameters)
a11 = (-cf-cr)/(m*u);
a12 = (((-cf*a)+(cr*b))/(m*u))-u;
a21 = ((-cf*a)+(cr*b))/(I*u);
a22 = ((-cf*a*a)-(cr*b*b))/(I*u);
b1 = cf/m;
b2 = (cf*a)/I;
% 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*del;
end
6 commentaires
Walter Roberson
le 26 Jan 2024
In particular see http://www.mathworks.com/help/matlab/math/parameterizing-functions.html for information on how to make cr and cf available to the function.
Star Strider
le 26 Jan 2024
Some of these problems were subsequently corrected.
It turns out to be a stiff system, and the zeros for initial conditions is another problem. (My approach to a solution as well as Comment by Sam Chak are in help wtih plotting ode function.)
.
Réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!