ode function 45 how to implement it

조회 수: 2 (최근 30일)
Zlatan
Zlatan 2024년 1월 25일
댓글: Star Strider 2024년 1월 26일
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
x0 = 2×1
0 0
% Solve the differential equation using ode45
[t, x] = ode45(@(t, x) myVehicleODE(t, x, delta_function(t)), tspan, initial_conditions);
Unrecognized function or variable '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
Walter Roberson
Walter Roberson 2024년 1월 26일
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
Star Strider 2024년 1월 26일
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.)
.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by