Using a matrix of values for a for loop

1 view (last 30 days)
James
James on 13 Apr 2015
Commented: the cyclist on 14 Apr 2015
For a project, I am needing to calculate several outputs following an iterative loop for a set of values. without copying the entire code, this is the structure for it
establishing constants
establishing matrix for values to step through, established using s=0.01:0.001:0.2 format
for loop for s =<0.2
while loop for iteration
outputs
end
end
For some reason, the code only iterates through one value of the matrix then ends. Is this format incorrect, or do I need to go about this a different way to ensure that it steps through the iteration and then through the s values.
[I moved the James' code from an answer to here. cyclist]
Here is the code since that seems to be causing an issue with resolving the problem
if true
% %%Constants for tires and other constants
CI=159.54; %cone index value. psi
br=18.8;%tire section width, in
bf=17.2;
dr=69.1; %overall unloaded tire diameter, in
df=52.4;
hr=13.1; %tire section height, in
hf=11.8;
deltar=2.45; %tire deflection, in
deltaf=2.4;
s=0.01:0.001:0.2; %slip, decimal value for 8% slip
Wrd=3119.541; %rear tire static weight per tire, lb
Wfd=1978.6488; %Front tire Static Weight per tire, lb
Wtot=10196.38; %total Tractor Weight including operator, lb
cog=36.6762; %distance from rear tire to center of gravity, in
dbh=20.9; %Draw bar height, in
WB=94.5;%Wheelbase length, in
Wrdnew=1;
Wfdnew=1;
Initial Calculations
for s
while abs(Wrd-Wrdnew)>0.00001 | abs(Wfd-Wfdnew)>0.00001
s=s
Wrd=Wrdnew; %outputs values for front and rear tire dynamic weight
Wfd=Wfdnew;
%%Calculation of Bn values for each tire
Bnr=(CI*br*dr/Wrd)*((1+5*(deltar/hr))/(1+3*(br/dr))); %equation to calculate initial Bn Value,
Rear tire
Bnf=(CI*bf*df/Wfd)*((1+5*(deltaf/hf))/(1+3*(bf/df))); %Equation to calculate Bn Value, Front Tire
%%Calculation of NetTraction for each set of tires
a=exp(-0.1*Bnr);
c=exp(-0.1*Bnf);
b=exp(-7.5*s);
NTr=Wrd*(0.88*(1-a)*(1-b)-(1/Bnr)-((0.5*s)/sqrt(Bnr))) %equation calculating net traction
NTf=Wfd*(0.88*(1-c)*(1-b)-(1/Bnr)-((0.5*s)/sqrt(Bnf)))
%%Calculation of Total NT value
NT=2*NTf+2*NTr
DBP=NT
%%Summing moments gives us the dynamic weight of the front axle
Wfdt=((Wtot*cog)-(DBP*dbh))/WB;
%%Summing forces gives us the dynamic weight of the rear axle
Wrdt=Wtot-Wfdt;
Wrdnew=Wrdt/2;
Wfdnew=Wfdt/2;
%%Calculation of Gross Traction and Tractive Efficent
Bnf=Bnf %outputs Bn values in command window
Bnr=Bnr
%%Calculation of gross traction for each tire and total
GTr=Wrd*(0.88*(1-a)*(1-b)+.04)
GTf=Wfd*(0.88*(1-a)*(1-b)+.04)
GTt=2*GTr+2*GTf
%%Calculates Tractive Efficency for each tire and total
TEf=(1-s)*(NTf/GTf)
TEr=(1-s)*(NTr/GTr)
TE=(1-s)*(NT/GTt)
%%outputs values of Wrd and Wfd
Wrd=Wrd
Wfd=Wfd
end
end
end
  1 Comment
the cyclist
the cyclist on 14 Apr 2015
Your code will not execute for me. It stops at the line
for s
which is not valid syntax.
Is that also what happens for you? Your explanation actually suggested that it ran to completion, but gave an unexpected result.

Sign in to comment.

Answers (1)

the cyclist
the cyclist on 13 Apr 2015
Not easy to say for sure, because the error seems to be syntactical, which is exactly what you left out. But, I think the syntax you want is
s = 0.01:0.001:0.2;
for ii = s
disp(ii)
end
and not
s = 0.01:0.001:0.2;
for s<=2
...
end

Categories

Find more on Tires and Vehicles in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!