- The error you are getting is in line 69, which says "plot(t,v)". The error is that vector lengths must be same.
- The above error has occured because you first used the variable "t" to iterate through the loop, which makes it take the values one by one, and doesn't make it an array.
- By the looks of it, you want a time axis and you are using "t" for it as of now.
- Another thing I noticed was that you are breaking out of the loop, and that break is occuring for me at "t = 3". When you execute the command t(50) = 51, MATLAB makes t an array of length 50, with the indices 2 to 49 set as 0.
- Now you can see why the size of the vectors is an issue. I would suggest to make a different array, in which you update the indices on the go; you can append using ";" operator in vectors. The updated code would look as follows.
How can i solve this dynamic model problem for a formula car?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello, everyone.
I am trying to code a dynamic model of a racecar, i'm trying to compare an All wheel drive setup to a Rear wheel drive setup.
I keep running into errors. Could you guys help me figure out what i'm doing wrong? Thank you in advance.
- Stef
% % Acceleration RWD vs AWD
clear; close all; clc
% Data
wb=1.55;
hG=0.28;
m=280;
Rw=0.45;
f=1.3;
W=60000;
cl=1.8;
cd=0.9;
Al=1.5;
Ad=0.75;
g=9.81;
rho=1.2;
dt=0.001;
etaD = 1;
%TorqueM(t) = W*Rw/v(t);
Jm = 0.28;
Jr = 0.08;
%tauTot = (z1 / z2) * 1/2;
tauTot = 0.3;
% Initialization
v(1) = 0.0001;
for t = 2:50
TorqueM(t) = W*Rw/v(t-1)
Fm(t) = (etaD * TorqueM(t)) / (Rw * tauTot);
Frot(t) = m * g * f;
Faero(t) = 0.5 * rho * Ad * cd * v(t-1)^2;
Jtot(t) = (etaD * Jm) / ( Rw^2 * tauTot^2) + m + (4 * Jr) / Rw^2;
a(t) = (Fm - Frot - Faero) / Jtot;
if a(t)<0
break
end
v(t) = a(t) * t;
s(t) = 0.5 * a(t) * t^2;
end
t(50)=51
plot(t,v)
a(end)
v(end)
%omegaA = v(t)/Rw
%2*Na+2*Np == m*g
%Wr=-m*g*f+v(t)-0.5
0 Commenti
Risposte (1)
Akshat
il 29 Feb 2024
Hi Stefano,
I see you are running into errors while running the given code.
I ran the code on my end, and here are the points which I found might be causing the errors:
clear; close all; clc
% Data
wb=1.55;
hG=0.28;
m=280;
Rw=0.45;
f=1.3;
W=60000;
cl=1.8;
cd=0.9;
Al=1.5;
Ad=0.75;
g=9.81;
rho=1.2;
dt=0.001;
etaD = 1;
%TorqueM(t) = W*Rw/v(t);
Jm = 0.28;
Jr = 0.08;
%tauTot = (z1 / z2) * 1/2;
tauTot = 0.3;
% Initialization
v(1) = 0.0001;
% Initialization of the time vector, with t = 1;
time_arr = [1];
for t = 2:50
TorqueM(t) = W*Rw/v(t-1)
Fm(t) = (etaD * TorqueM(t)) / (Rw * tauTot);
Frot(t) = m * g * f;
Faero(t) = 0.5 * rho * Ad * cd * v(t-1)^2;
Jtot(t) = (etaD * Jm) / ( Rw^2 * tauTot^2) + m + (4 * Jr) / Rw^2;
a(t) = (Fm - Frot - Faero) / Jtot;
if a(t)<0
break
end
% This is where we add new time stamps
time_arr = [time_arr,t];
v(t) = a(t) * t;
s(t) = 0.5 * a(t) * t^2;
end
% t(50)=51
plot(time_arr,v)
a(end)
v(end)
%omegaA = v(t)/Rw
%2*Na+2*Np == m*g
%Wr=-m*g*f+v(t)-0.5
You can update the above stated code as per your requirements, but it is free from errors as of now.
Hope this helps!
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!