Iterating/repeating input values to plot against outputs without turning the input into a matrix?

I'd like iterate/repeat specific input values so that I can quickly generate plots of one of my changing inputs against an output. For example, to see how wheelbase(L) affects lateral force(NetFy). My initial thought was to turn the input of interest into a matrix. However, my calculations use matrix operations to generate my outputs and I get a concatentation error if I turn an input into a matrix.
How can I iterate my inputs and plot them against the resulting outputs? Thanks for any insight you can provide. I've attached my script.
%Practice Bicycle Model
%Inputs%
VDW = 660; %Vehicle + Driver Weight (lbf)
FWD = 0.45; %Front Weight Distribution (%)
L = 5.25; %Wheelbase (ft)
Cf = 1150; %Front Tire Cornering Stiffness (lbf/rad)
Cr = 1500; %Rear Tire Cornering Stiffness (lbf/rad)
I = 70; %Yaw Inertia (lbm-ft^2)
V = 45; %Vehicle Speed (mph)
St = 6; %Steering Input (deg)
m=VDW/32.1740486; %mass (lbm)
%Calcualations%
%Find a and b (dist. from CG to front and rear axle, repsectively)
Wf = VDW*FWD; %Weight of front axle
Wr = VDW*(1-FWD); %Weight of rear axle
%a+b=L (eqn1)
%Wf*a+Wr*b=0 (eqn2)
A = [-Wf Wr;1 1]; %[a b] matrix
Lm = [0;L]; %[L] Matrix
X = linsolve(A,Lm);
a=X(1,1); b=X(2,1);
%Define Matrix Elements
Y1 = Cf*(St*(pi/180));
Y2 = (a*Cf)*(St*(pi/180));
X1 = (Cf+Cr);
X2 = ((a*Cf-b*Cr)/(V))-(m*(V));
X3 = (a*Cf-b*Cr);
X4 = (a^2*Cf+b^2*Cr)/(V);
%Solve System of Equations for Sideslip and Yaw Velocity
Z1=[X1 X2;X3 X4];
Z2=[Y1;Y2];
Z3=Z1\Z2;
disp('Sideslip Angle (deg):')
disp(Z3(1,1)*(180/pi))
disp('Yaw Velocity (rad/s):')
disp(Z3(2,1))
%Find Parameters to Calculate Slip Angle
B=-(Z3(1,1)*(180/pi)); %Sideslip Angle (deg)
r=(Z3(2,1))*(180/pi); %Yaw Velocity (deg/s)
v=B*V; %Lateral Velocity (mph)
%Calculate Front and Rear Slip Angle
saf=((v+a*r)/V)-St; %Slip Angle Front (deg)
sar=(v-b*r)/V; %Slip Angle Rear (deg)
%Calculate Lateral Force on Tires
Fyf = (Cf/(180/pi))*saf; %Lateral Force on front tire (lbf)
Fyr = (Cr/(180/pi))*sar; %Lateral Force on rear tire (lbf)
%Net Lateral Force
NetFy = Fyf + Fyr;
disp('Net Lateral Force (lbf): ')
disp(NetFy)
%Calculate Lateral Gs
g=abs(NetFy/VDW);
disp('Lateral Acceleration (g): ')
disp(g)

Answers (1)

You can use ndgrid to vary all the perameters you want, although the matrix sizes can become quite large and run-time will increase. Try smaller changes in the parameters to reduce run-time, or just change a few parameters at once.
VDW = 600:10:700; %Vehicle + Driver Weight (lbf)
FWD = .4:.01:0.5; %Front Weight Distribution (%)
L = 4.5:.1:6; %Wheelbase (ft)
Cf = 1000:50:1250; %Front Tire Cornering Stiffness (lbf/rad)
Cr = 1350:50:1650; %Rear Tire Cornering Stiffness (lbf/rad)
I = 60:2:80; %Yaw Inertia (lbm-ft^2)
V = 30:5:60; %Vehicle Speed (mph)
St = 4:8; %Steering Input (deg)
[VDW,FWD,L,Cf,Cr,I,V,St]=ndgrid(VDW,FWD,L,Cf,Cr,I,V,St);
m=VDW./32.1740486; %mass (lbm)
Wf = VDW.*FWD; %Weight of front axle
Wr = VDW.*(1-FWD); %Weight of rear axle
NetFy=zeros(size(Wf));Fyr=zeros(size(Wf));Fyf=zeros(size(Wf));sar=zeros(size(Wf));
saf=zeros(size(Wf));v=zeros(size(Wf));r=zeros(size(Wf));g=zeros(size(Wf));B=zeros(size(Wf));
for k=1:numel(Wf)
A = [-Wf(k) Wr(k);1 1]; %[a b] matrix
Lm = [0;L(k)]; %[L] Matrix
X = linsolve(A,Lm);
a=X(1,1); b=X(2,1);
%Define Matrix Elements
Y1 = Cf(k)*(St(k)*(pi/180));
Y2 = (a*Cf(k))*(St(k)*(pi/180));
X1 = (Cf(k)+Cr(k));
X2 = ((a*Cf(k)-b*Cr(k))/(V(k)))-(m(k)*(V(k)));
X3 = (a*Cf(k)-b*Cr(k));
X4 = (a^2*Cf(k)+b^2*Cr(k))/(V(k));
%Solve System of Equations for Sideslip and Yaw Velocity
Z1=[X1 X2;X3 X4];
Z2=[Y1;Y2];
Z3=Z1\Z2;
B(k)=-(Z3(1,1)*(180/pi)); %Sideslip Angle (deg)
r(k)=(Z3(2,1))*(180/pi); %Yaw Velocity (deg/s)
v(k)=B(k)*V(k); %Lateral Velocity (mph)
%Calculate Front and Rear Slip Angle
saf(k)=((v(k)+a*r(k))/V(k))-St(k); %Slip Angle Front (deg)
sar(k)=(v(k)-b*r(k))/V(k); %Slip Angle Rear (deg)
%Calculate Lateral Force on Tires
Fyf(k) = (Cf(k)/(180/pi))*saf(k); %Lateral Force on front tire (lbf)
Fyr(k) = (Cr(k)/(180/pi))*sar(k); %Lateral Force on rear tire (lbf)
%Net Lateral Force
NetFy(k) = Fyf(k) + Fyr(k);
g(k)=abs(NetFy(k)/VDW(k));
end

Categories

Find more on Aerospace Blockset in Help Center and File Exchange

Products

Release

R2021b

Asked:

on 22 Mar 2022

Commented:

on 23 Mar 2022

Community Treasure Hunt

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

Start Hunting!