フィルターのクリア

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 Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by