iam trying to solve a system of differential equations of car model using ode45 but I am always get an error

10 views (last 30 days)
clear all
clc
% 8 DOF Car Model
%% Model Parameters
% Adhesion Limit
Meo = 0.85
Meo = 0.8500
% Distance of center of gravity C.G from front axle in meters
a = 1.203
a = 1.2030
% Front and rear track width in meters
Bf = 1.33
Bf = 1.3300
Br = 1.33
Br = 1.3300
% Distance of C.G from rear axle in meters
b = 1.217
b = 1.2170
% Roll axis torsional damping (Nm/rad/sec)
Cphi = 3511.6
Cphi = 3.5116e+03
% Roll axis torsional stiffness (Nm/rad)
Kphi = 66185.8
Kphi = 6.6186e+04
% Cornering stiffness of all tire in (N/rad)
Ccfr = 30000
Ccfr = 30000
Ccfl = 30000
Ccfl = 30000
Ccrr = 30000
Ccrr = 30000
Ccrl = 30000
Ccrl = 30000
% Longitudinal stiffness of all tires in (N/rad)
Cxfr = 50000
Cxfr = 50000
Cxfl = 50000
Cxfl = 50000
Cxrr = 50000
Cxrr = 50000
Cxrl = 50000
Cxrl = 50000
% Distance of the sprung mass C.G from the roll axes in meters
e = 0.2
e = 0.2000
% Gravitational acceleration in (m/sec^2)
g = 10
g = 10
% Height of the sprung mass C.G in meters
h = 0.5
h = 0.5000
% Vehicle moment of inertia about roll axis in (Kg.m^2)
Ixx = 750
Ixx = 750
% Sprung mass product of Inertia in (Kg.m^2)
Ixz = 0
Ixz = 0
% Wheel moment of inertia in (kg.m^2)
Iw = 2.1
Iw = 2.1000
% Vehicle moment of inertia about yaw axis
Iz = 2500
Iz = 2500
% Length of the wheel base in meters
l = 2.42
l = 2.4200
% Vehicle total mass in kg
m = 1280
m = 1280
% Vehicle sprung mass in kg
ms = 1160
ms = 1160
% Radius of the wheel in meters
rw = 0.3
rw = 0.3000
%y = ones(100,100);
%% Let aerodynamic drag force = 20 N and Rolling Resistance be
Faero = 20
Faero = 20
%%Inputs Section
Ster_Ang_Fr = 30 %(in degres)
Ster_Ang_Fr = 30
Ster_Ang_Fl = 30
Ster_Ang_Fl = 30
Ster_Ang_rr = 0
Ster_Ang_rr = 0
Ster_Ang_rl = 0
Ster_Ang_rl = 0
T_FR = 0 % (N.m)
T_FR = 0
T_FL = 0
T_FL = 0
T_RR = 150
T_RR = 150
T_Rl = 150
T_Rl = 150
tspan=[0 10];
y0=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
%% Solving the four ODE's of main Equations for motion
y = ones(16,1)
y = 16×1
1 1 1 1 1 1 1 1 1 1
[t,y] = ode45(@ODE_MO , tspan, y0);
dydt = 16×1
0 0 0 0 0 0 0 0 0 0
Unrecognized function or variable 'y'.

Error in solution>TireForce_Long_FR (line 221)
Fz_FR = Fzfr(y(1),y(2),y(3),y(4),y(5),y(7));

Error in solution>F_X_FR (line 267)
Force_X_FR = (TireForce_Long_FR()*cosd(Ster_Ang_Fr))-(TireForce_Side_FR()*sind(Ster_Ang_Fr))

Error in solution>ODE_MO (line 76)
dydt(2,:) = (F_X_FR()+F_X_FL()+F_X_RR()+F_X_RL()-Faero-Faero+m*y(4)*y(6))/m;

Error in odearguments (line 92)
f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0.

Error in ode45 (line 104)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
function dydt = ODE_MO (t,y)
dydt= zeros(16,1)
dydt(1,:) = y(2);
dydt(2,:) = (F_X_FR()+F_X_FL()+F_X_RR()+F_X_RL()-Faero-Faero+m*y(4)*y(6))/m;
dydt(3,:) = y(4);
dydt(4,:) = F_Y_FR()+F_Y_FL()+F_Y_RR()+F_Y_RL()-(m*y(2)*y(6))-(ms.*e.*dydt(8,:));
dydt(5,:) = y(6);
dydt(6,:) = (Ixx*dydt(8,:)+ (a*(F_Y_FR()+F_Y_FL()))-(b*(F_Y_RR()+F_Y_RL()))+((Bf/2)*(F_X_FR()+F_X_FL())+((Br/2)*(F_X_RR()-F_X_RL()))))/Iz;
dydt(7,:) = y(8);
dydt(8,:) = (-ms*e*dydt(4,:))-(ms*e*y(2)*y(6))+(Ixz*dydt(6,:))+(ms*g*e*sind(y(7)))-(Kphi*y(7))-(Cphi*y(8))
dydt(9,:) = y(10);
dydt(10,:) = T_FR-(rw*TireForce_Long_FR())/Iw;
dydt(11,:) = y(12);
dydt(12,:) = T_FL-(rw*TireForce_Long_FL())/Iw;
dydt(13,:) = y1(14);
dydt(14,:) = T_RR-(rw*TireForce_Long_RR())/Iw;
dydt(15,:) = y1(16);
dydt(16,:) = T_RL-(rw*TireForce_Long_RL())/Iw;
end
%% solving the equations of Rotation of motion of wheels
% [t1,x1] = ode45 ( @DEQ1 , [0 10],[0 0 0 0 0 0 0 0] )
% function dydt1 = DEQ1 (t1,y1)
% dydt1 = [ y1(2);
% T_FR-(rw*TireForce_Long_FR())/Iw;
% y1(4);
% T_FL-(rw*TireForce_Long_FL())/Iw;
% y1(6);
% T_RR-(rw*TireForce_Long_RR())/Iw;
% y1(8);
% T_RL-(rw*TireForce_Long_RL())/Iw; ]
%end
%% Vertical Weight Transfere Loads Functions
function fzfr = Fzfr(ai,bi,ci,di,ei,fi)
ax = (bi-(ci.*ei))
ay = (di+(ai.*ei))
fzfr = (m.*g.*b/2*l)-(h.*m.*ax/2*l)-(h*Faero/2*l)-((h*ms.*ay/Bf)*(b/l))+((ms*g*e*sind(fi)/Bf)*b/l)
end
function fzfl = Fzfl(ai,bi,ci,di,ei,fi)
ax = (bi-(ci*ei))
ay = (di+(ai*ei))
fzfl = (m*g*b/2*l)-(h*m*ax/2*l)-(h*Faero/2*l)+((h*ms*ay/Bf)*(b/l))-((ms*g*e*sind(fi)/Bf)*b/l)
end
function fzrr = Fzrr(ai,bi,ci,di,ei,fi)
ax = (bi-(ci*ei))
ay = (di+(ai*ei))
fzrr = (m*g*a/2*l)+(h*m*ax/2*l)+(h*Faero/2*l)-((h*ms*ay/Br)*(a/l))+((ms*g*e*sind(fi)/Br)*(a/l))
end
function fzrl = Fzrl(ai,bi,ci,di,ei,fi)
ax = (bi-(ci*ei))
ay = (di+(ai*ei))
fzrl = (m*g*a/2*l)+(h*m*ax/2*l)+(h*Faero/2*l)+((h*ms*ay/Br)*(a/l))+((ms*g*e*sind(fi)/Br)*(a/l))
end
%% Tire slip Angles Fnctions
function Slip_Angle_FR= Sli_Ang_FR(ai,bi,ci,Ster_Ang_Fr)
Slip_Angle_FR = Ster_Ang_Fr - atan((bi+(a*ci))/(ai-((Bf/2)*ci)))
end
function Slip_Angle_FL= Sli_Ang_FL(ai,bi,ci,Ster_Ang_Fl)
Slip_Angle_FL = Ster_Ang_Fl - atan((bi+(a*ci))/(ai+((Bf/2)*ci)))
end
function Slip_Angle_RR= Sli_Ang_RR(ai,bi,ci,Ster_Ang_rr)
Slip_Angle_RR = Ster_Ang_rr - atan((bi-(b*ci))/(ai-((Br/2)*ci)))
end
function Slip_Angle_RL= Sli_Ang_RL(ai,bi,ci,Ster_Ang_rl)
Slip_Angle_RL = Ster_Ang_rl - atan((bi-(b*ci))/(ai+((Br/2)*ci)))
end
%% Wheel Plan Speed (Actual Speed)
function WPSFR = Wheel_PlanSpeed_FR(ai,bi,ci,Ster_Ang_Fr)
WPSFR = ((ai-((Bf/2)*ci))*cosd(Ster_Ang_Fr)) + (((bi)+(a*ci))*sind(Ster_Ang_Fr))
end
function WPSFL = Wheel_PlanSpeed_FL(ai,bi,ci,Ster_Ang_Fl)
WPSFL = ((ai+((Bf/2)*ci))*cosd(Ster_Ang_Fl)) + (((bi)+(a*ci))*sind(Ster_Ang_Fl))
end
function WPSRR = Wheel_PlanSpeed_RR(ai,bi,ci,Ster_Ang_rr)
WPSRR = ((ai-((Br/2)*ci))*cosd(Ster_Ang_rr)) + (((bi)-(b*ci))*sind(Ster_Ang_rr))
end
function WPSRL = Wheel_PlanSpeed_RL(ai,bi,ci,Ster_Ang_rl)
WPSRL = ((ai+((Br/2)*ci))*cosd(Ster_Ang_rl)) + (((bi)-(b*ci))*sind(Ster_Ang_rl))
end
%% Tire Slip Ratio Fuction
function Slip_FR = Slip_Ratio_FR(rw,ai)
bi = Wheel_PlanSpeed_FR(x(1),x(3),x(5),Ster_Ang_Fr)
Slip_FR = ((rw*ai)-bi)/max((rw*ai),bi)
end
function Slip_FL = Slip_Ratio_FL(rw,ai)
bi = Wheel_PlanSpeed_FL(x(1),x(3),x(5),Ster_Ang_Fl)
Slip_FL = ((rw*ai)-bi)/max((rw*ai),bi)
end
function Slip_RR = Slip_Ratio_RR(rw,ai)
bi = Wheel_PlanSpeed_RR(x(1),x(3),x(5),Ster_Ang_rr)
Slip_RR = ((rw*ai)-bi)/max((rw*ai),bi)
end
function Slip_RL = Slip_Ratio_RL(rw,ai)
bi = Wheel_PlanSpeed_RL(x(1),x(3),x(5),Ster_Ang_rl)
Slip_RL = ((rw*ai)-bi)/max((rw*ai),bi)
end
%% Tire Model %%%%%%%%%%%%%%%%
% Side Forces
function TF_Side_FR = TireForce_Side_FR()
% variables values
Fz_FR = Fzfr(y(1,:),y(2,:),y(3,:),y(4,:),y(5,:),y(7,:))
Slip_ratio_FR = Slip_Ratio_FR(rw,x1(1))
Slip_Angle_FR = Sli_Ang_FR(dydt(1),dydt(3),dydt(5),Ster_Ang_Fr)
%Scaling Factor
LC = ( Meo * Fz_FR * (1-Slip_ratio_FR) / 2 * sqrt((Cxfr^2*Slip_ratio_FR^2)+ Ccfr^2*tand(Slip_Angle_FR)^2))
GA = (Meo - 1.6 * tand(Slip_Angle_FR) + 1.155)
TF_Side_FR = ((Ccfr*tand(Slip_Angle_FR))/1+Slip_ratio_FR)* LC * GA
end
function TF_Side_FL = TireForce_Side_FL()
% variables values
Fz_FL = Fzfl(y(1,:),y(2,:),y(3,:),y(4,:),y(5,:),y(7,:))
Slip_ratio_FL = Slip_Ratio_FL(rw,x1(3))
Slip_Angle_FL = Sli_Ang_FL(dydt(1),dydt(3),dydt(5),Ster_Ang_Fl)
%Scaling Factor
LC = ( Meo * Fz_FL * (1-Slip_ratio_FL) / 2 * sqrt((Cxfl^2*Slip_ratio_FL^2)+ Ccfl^2*tand(Slip_Angle_FL)^2))
GA = (Meo - 1.6 * tand(Slip_Angle_FL) + 1.155)
TF_Side_FL = ((Ccfl*tand(Slip_Angle_FL))/1+Slip_ratio_FL)* LC * GA
end
function TF_Side_RR = TireForce_Side_RR()
% variables values
Fz_RR = Fzrr(y(1,:),y(2,:),y(3,:),y(4,:),y(5,:),y(7,:))
Slip_ratio_RR = Slip_Ratio_RR(rw,x1(5))
Slip_Angle_RR = Sli_Ang_RR(dydt(1),dydt(3),dydt(5),Ster_Ang_rr)
%Scaling Factor
LC = ( Meo * Fz_RR * (1-Slip_ratio_RR) / 2 * sqrt((Cxrr^2*Slip_ratio_RR^2)+ Ccrr^2*tand(Slip_Angle_RR)^2))
GA = (Meo - 1.6 * tand(Slip_Angle_RR) + 1.155)
TF_Side_RR = ((Ccrr*tand(Slip_Angle_RR))/1+Slip_ratio_RR)* LC * GA
end
function TF_Side_RL = TireForce_Side_RL()
% variables values
Fz_RL = Fzrl(y(1,:),y(2,:),y(3,:),y(4,:),y(5,:),y(7,:))
Slip_ratio_RL = Slip_Ratio_RL(rw,x1(7))
Slip_Angle_RL = Sli_Ang_RL(dydt(1),dydt(3),dydt(5),Ster_Ang_rl)
%Scaling Factor
LC = ( Meo * Fz_RL * (1-Slip_ratio_RL) / 2 * sqrt((Cxrl^2*Slip_ratio_RL^2)+ Ccrl^2*tand(Slip_Angle_RL)^2))
GA = (Meo - 1.6 * tand(Slip_Angle_RL) + 1.155)
TF_Side_RL = ((CcrL*tand(Slip_Angle_RL))/1+Slip_ratio_RL)* LC * GA
end
% Longitudinal Forces
function TF_Long_FR = TireForce_Long_FR()
% variables values
Fz_FR = Fzfr(y(1),y(2),y(3),y(4),y(5),y(7));
Slip_ratio_FR = Slip_Ratio_FR(rw,x1(1));
Slip_Angle_FR = Sli_Ang_FR(dydt(1),dydt(3),dydt(5),Ster_Ang_Fr);
%Scaling Factor
LC = ( Meo * Fz_FR * (1-Slip_ratio_FR) / 2 * sqrt((Cxfr^2*Slip_ratio_FR^2)+ Ccfr^2*tand(Slip_Angle_FR)^2))
GSFR = ((1.15 - 0.75*Meo)*(Slip_ratio_FR^2))-((1.63-0.75*Meo)*Slip_ratio_FR + 1.27);
%
TF_Long_FR = ((Cxfr*Slip_ratio_FR)/1+Slip_ratio_FR)*LC*GSFR;
end
function TF_Long_FL = TireForce_Long_FL()
% variables values
Fz_FL = Fzfl(y(1,:),y(2,:),y(3,:),y(4,:),y(5,:),y(7,:))
Slip_ratio_FL = Slip_Ratio_FL(rw,x1(3))
Slip_Angle_FL = Sli_Ang_FL(dydt(1),dydt(3),dydt(5),Ster_Ang_Fl)
%Scaling Factor
LC = ( Meo * Fz_FL * (1-Slip_ratio_FL) / 2 * sqrt((Cxfl^2*Slip_ratio_FL^2)+ Ccfl^2*tand(Slip_Angle_FL)^2))
GSFL = ((1.15 - 0.75*Meo)*(Slip_ratio_FL^2))-((1.63-0.75*Meo)*Slip_ratio_FL + 1.27)
%
TF_Long_FL = ((Cxfl*Slip_ratio_FL)/1+Slip_ratio_FL)*LC*GSFR;
end
function TF_Long_RR = TireForce_Long_RR()
% variables values
Fz_RR = Fzrr(y(1,:),y(2,:),y(3,:),y(4,:),y(5,:),y(7,:))
Slip_ratio_RR = Slip_Ratio_RR(rw,x1(5))
Slip_Angle_RR = Sli_Ang_RR(dydt(1),dydt(3),dydt(5),Ster_Ang_rr)
%Scaling Factor
LC = ( Meo * Fz_RR * (1-Slip_ratio_RR) / 2 * sqrt((Cxrr^2*Slip_ratio_RR^2)+ Ccrr^2*tand(Slip_Angle_RR)^2))
GSRR = ((1.15 - 0.75*Meo)*(Slip_ratio_RR^2))-((1.63-0.75*Meo)*Slip_ratio_RR + 1.27)
%
TF_Long_RR = ((Cxrr*Slip_ratio_RR)/1+Slip_ratio_RR)*LC*GSRR
end
function TF_Long_RL = TireForce_Long_RL()
% variables values
Fz_RL = Fzrl(y(1,:),y(2,:),y(3,:),y(4,:),y(5,:),y(7,:))
Slip_ratio_RL = Slip_Ratio_RL(rw,x1(7))
Slip_Angle_RL = Sli_Ang_RL(dydt(1),dydt(3),dydt(5),Ster_Ang_rl)
%Scaling Factor
LC = ( Meo * Fz_RL * (1-Slip_ratio_RL) / 2 * sqrt((Cxrl^2*Slip_ratio_RL^2)+ Ccrl^2*tand(Slip_Angle_RL)^2))
GSRL = ((1.15 - 0.75*Meo)*(Slip_ratio_RL^2))-((1.63-0.75*Meo)*Slip_ratio_RL + 1.27)
%
TF_Long_RL = ((Cxrl*Slip_ratio_RL)/1+Slip_ratio_RL)*LC*GSRL
end
%% Tire Forces that is scaled with Respect to long and Lateral
% longitudinal Force
function Force_X_FR = F_X_FR()
Force_X_FR = (TireForce_Long_FR()*cosd(Ster_Ang_Fr))-(TireForce_Side_FR()*sind(Ster_Ang_Fr))
end
function Force_X_FL = F_X_FL()
Force_X_FL = (TireForce_Long_FL()*cosd(Ster_Ang_Fl))-(TireForce_Side_FL()*sind(Ster_Ang_Fl))
end
function Force_X_RR = F_X_RR()
Force_X_RR = (TireForce_Long_RR()*cosd(Ster_Ang_rr))-(TireForce_Side_RR()*sind(Ster_Ang_rr))
end
function Force_X_RL = F_X_RL()
Force_X_RL = (TireForce_Long_RL()*cosd(Ster_Ang_rl))-(TireForce_Side_RL()*sind(Ster_Ang_rl))
end
% side Force
function Force_Y_FR = F_Y_FR()
Force_Y_FR = (TireForce_Long_FR()*sind(Ster_Ang_Fr))+(TireForce_Side_FR()*cosd(Ster_Ang_Fr))
end
function Force_Y_FL = F_Y_FL()
Force_Y_FL = (TireForce_Long_FL()*sind(Ster_Ang_Fl))+(TireForce_Side_FL()*cosd(Ster_Ang_Fl))
end
function Force_Y_RR = F_Y_RR()
Force_Y_RR = (TireForce_Long_RR()*sind(Ster_Ang_rr))+(TireForce_Side_RR()*cosd(Ster_Ang_rr))
end
function Force_Y_RL = F_Y_RL()
Force_Y_RL = (TireForce_Long_RL()*sind(Ster_Ang_rl))+(TireForce_Side_RL()*cosd(Ster_Ang_rl))
end

Accepted Answer

Sam Chak
Sam Chak on 9 Oct 2023
The code is quite messy, with numerous unformatted local functions scattered throughout, making it visually challenging to troubleshoot. Additionally, there are some typographical errors in the equations.
However, I spent several hours rectifying the code's core structure, resulting in the ode45 solver running without errors. Nonetheless, you still need to properly rewrite the nested functions responsible for calculating the forces on the wheels and tires, both front and rear, on both the right and left sides.
Best of luck!
tspan = [0 10];
s0 = zeros(1, 16);
[t, s] = ode45(@ODE_MO, tspan, s0);
% Plotting state variables, s1 to s16
figure(1)
for j = 1:length(s0)
subplot(4,4,j)
plot(t, s(:,j)), grid on
str = sprintf('s_{%1d}', j);
title(str, 'FontSize', 9);
end
%% 8-DOF Car Model
function dsdt = ODE_MO(t, s)
% Model Parameters
Meo = 0.85;
a = 1.203;
Bf = 1.33;
Br = 1.33;
b = 1.217;
Cphi = 3511.6;
Kphi = 66185.8;
Ccfr = 30000;
Ccfl = 30000;
Ccrr = 30000;
Ccrl = 30000;
Cxfr = 50000;
Cxfl = 50000;
Cxrr = 50000;
Cxrl = 50000;
e = 0.2;
g = 10;
h = 0.5;
Ixx = 750;
Ixz = 0;
Iw = 2.1;
Iz = 2500;
l = 2.42;
m = 1280;
ms = 1160;
rw = 0.3;
% Inputs Section
Ster_Ang_Fr = 30;
Ster_Ang_Fl = 30;
Ster_Ang_rr = 0;
Ster_Ang_rl = 0;
T_FR = 0;
T_FL = 0;
T_RR = 150;
T_RL = 150; % <-- fixed
% Definitions of states
x = s(1);
xdot = s(2); % Vx
y = s(3);
ydot = s(4); % Vy
psi = s(5);
psidot = s(6); % Psi
phi = s(7);
phidot = s(8); % R
% Decoupling ψ" & ϕ" by getting the inverse of Inertia matrix
f1 = a*(Fyfr + Fyfl) - b*(Fyrr + Fyrl) + Bf/2*(Fxfl - Fxfr) + Br/2*(Fxrl - Fxrr);
f2 = - ms*e*(Fyfr + Fyfl + Fyrr + Fyrl - m*xdot*psidot)/m - ms*e*xdot*psidot + ms*g*e*sin(phi) - Kphi*phi - Cphi*phidot;
MI = [Iz -Ixx; -Ixz Ixx-(ms*e*ms*e/m)]; % Iz*psiddot - Ixx*phiddot = f1;
F = [f1; f2]; % - Ixz*psiddot + Ixx*phiddot - (ms*e*ms*e/m)*phiddot = f2;
fcn = MI\F;
psiddot = fcn(1); % ψ"
phiddot = fcn(2); % ϕ"
xddot = (Fxfr + Fxfl + Fxrr + Fxrl - Faero - Froll + m*ydot*psidot)/m;
yddot = (Fyfr + Fyfl + Fyrr + Fyrl - ms*e*phiddot - m*xdot*psidot)/m;
%% Equations of Motion
dsdt = zeros(16, 1); % initialization
%% Car dynamics
% Longitudinal motion
dsdt(1) = s(2); % x'
dsdt(2) = xddot;
% Lateral motion
dsdt(3) = s(4); % y'
dsdt(4) = yddot;
% Yaw motion
dsdt(5) = s(6); % psi'
dsdt(6) = psiddot;
% Roll motion
dsdt(7) = s(8); % phi'
dsdt(8) = phiddot;
%% Wheel dynamics
% Front right wheel
dsdt(9) = s(10);
dsdt(10) = (T_FR - rw*Ftfr)/Iw;
% Front left wheel
dsdt(11) = s(12);
dsdt(12) = (T_FL - rw*Ftfl)/Iw;
% Rear right wheel
dsdt(13) = s(14);
dsdt(14) = (T_RR - rw*Ftrr)/Iw;
% Rear left wheel
dsdt(15) = s(16);
dsdt(16) = (T_RL - rw*Ftrl)/Iw;
%% Nested Functions
function out = Fxfr()
out = 1;
end
function out = Fxfl()
out = 1;
end
function out = Fxrr()
out = 1;
end
function out = Fxrl()
out = 1;
end
function out = Faero()
out = 20;
end
function out = Froll()
out = 1;
end
function out = Fyfr()
out = 1;
end
function out = Fyfl()
out = 1;
end
function out = Fyrr()
out = 1;
end
function out = Fyrl()
out = 1;
end
function out = Ftfr()
out = 1;
end
function out = Ftfl()
out = 1;
end
function out = Ftrr()
out = 1;
end
function out = Ftrl()
out = 1;
end
end
  2 Comments
Mostafa Salah
Mostafa Salah on 11 Oct 2023
Edited: Mostafa Salah on 11 Oct 2023
Thank you so much for your time and your clarification
But IF I may ask in the part of decoupling
% Decoupling ψ" & ϕ" by getting the inverse of Inertia matrix
f1 = a*(Fyfr + Fyfl) - b*(Fyrr + Fyrl) + Bf/2*(Fxfl - Fxfr) + Br/2*(Fxrl - Fxrr);
f2 = - ms*e*(Fyfr + Fyfl + Fyrr + Fyrl - m*xdot*psidot)/m - ms*e*xdot*psidot + ms*g*e*sin(phi) - Kphi*phi - Cphi*phidot;
MI = [Iz -Ixx; -Ixz Ixx-(ms*e*ms*e/m)]; % Iz*psiddot - Ixx*phiddot = f1;
F = [f1; f2]; % - Ixz*psiddot + Ixx*phiddot - (ms*e*ms*e/m)*phiddot = f2;
fcn = MI\F;
psiddot = fcn(1); % ψ"
phiddot = fcn(2); % ϕ"
I want to know how did you decoupled this variables in details and did you get help from any reference or paper
Sam Chak
Sam Chak on 11 Oct 2023
Nope @Mostafa Salah, I didn't refer to any special paper. But I remember solving simultaneous linear equations () using matrices in Grade 10. The coupled {ψ", ϕ"} problem is exactly a system of linear equations that can be solved using matrices. In Grade 9, we learned how to solve the system using the substitution method, which is equivalent to the Gauss Elimination method. In Grade 10, we learned a shortcut formula called "Cramer's Rule" to solve a 2×2 matrix system instead of finding the inverse of the matrix as in .
In the code, fcn = MI\F involves left matrix division, which is not typically taught in school. Even my math teacher was not familiar with it.

Sign in to comment.

More Answers (1)

Dyuman Joshi
Dyuman Joshi on 8 Oct 2023
You are using multiple variables inside (almost all of the) local functions but you have not defined them nor have you passed them as input.
For example -
function TF_Long_RR = TireForce_Long_RR()
% variables values
Fz_RR = Fzrr(y(1,:),y(2,:),y(3,:),y(4,:),y(5,:),y(7,:))
Slip_ratio_RR = Slip_Ratio_RR(rw,x1(5))
Slip_Angle_RR = Sli_Ang_RR(dydt(1),dydt(3),dydt(5),Ster_Ang_rr)
%Scaling Factor
LC = ( Meo * Fz_RR * (1-Slip_ratio_RR) / 2 * sqrt((Cxrr^2*Slip_ratio_RR^2)+ Ccrr^2*tand(Slip_Angle_RR)^2))
GSRR = ((1.15 - 0.75*Meo)*(Slip_ratio_RR^2))-((1.63-0.75*Meo)*Slip_ratio_RR + 1.27)
%
TF_Long_RR = ((Cxrr*Slip_ratio_RR)/1+Slip_ratio_RR)*LC*GSRR
end
From where will MATLAB find the variables y, Fzrr, rw, x1 etc. to compute the output?
Also, consider using semi-colons.
  2 Comments
Mostafa Salah
Mostafa Salah on 9 Oct 2023
Edited: Sam Chak on 9 Oct 2023
"y" is a global variable that is returned from the solution of the ODE. So, I think there is no need to redefine this variable.
I am trying to solve this model, which is highly coupled. Here is a photo of the main equations I am using.
Meanwhile, the longitudinal and lateral forces acting on the car are defined in the local functions, and you can find their implementation in the accompanying code.
Torsten
Torsten on 9 Oct 2023
Edited: Torsten on 9 Oct 2023
"y" is a global variable that is returned from the solution of the ODE. So, I think there is no need to redefine this variable.
All variables used in functions need to be supplied - so you have to put them in the input lists to your functions or you have to use your functions as nested functions to function "ODE_MO".
Take a look here to see how this works:
Equations (3) and (4) contain several derivatives, not only one. Thus you will have to write your ODE system as M * y' = f(t,y) and either supply M and f separately (using the mass matrix option for the matrix M in ode15s) or - if M is nonsingular - by solving for y' by y' = M^(-1) * f(t,y).

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!