Nested for and while loop continuously looping and not assigning values in table

1 view (last 30 days)
A two part question. Part one, I've been using an iterative loop to calculate values for a set of values given sets of equations. The goal of the code is to get the values to converge and then move to a new value and repeat the process until all of the values have been calculated. The code I've written, however, continuously loops through the values without stopping. What could cause then?
Part two, I need to display the found values in a table when all is said and done, in one single table, for some reason, the code as written wants to put each set of values in a separate table. What is causing this problem. The code is below
close all; clear all; format compact; format long g;
%%Initial Calculations
while abs(Wrd-Wrdnew)>0.00001 abs(Wfd-Wfdnew)>0.00001 && s<0.2
for s= 0.01:0.001:0.2
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 Efficency
%%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);
TEFF=TEf*100;
TERR=TEr*100;
%%outputs values of Wrd and Wfd
Wrd=Wrd;
Wfd=Wfd;
T=table([s;s],[Wfs; Wrs],[Wrd;Wfd],[Bnf;Bnr],[GTf;GTr],[NTf;NTr],[TEFF;TERR]);
T.Properties.VariableNames={'Slip', 'Static_Weight','Dynamic_Weight','Dimensionless_Ratio','Gross_Traction','Pull_NT','TE'}; T.Properties.RowNames={ 'Front Tire', 'Rear Tire'} 'Net Traction total' NT
end
end
  3 Comments
James
James on 14 Apr 2015
for some reason, every time i try to copy the code into the comment it wants to break it up like it is before.. not sure why it does that
Geoff Hayes
Geoff Hayes on 15 Apr 2015
Edited: Geoff Hayes on 15 Apr 2015
James - just highlight the code portion of your post and press the {}Code button.
Also, why is your while loop have a duplicated first condition
while abs(Wrd-Wrdnew)>0.00001 abs(Wfd-Wfdnew)>0.00001 && s<0.2
And the above line of code is accessing variables that haven't been defined so is bound to generate the
Undefined function or variable 'Wrd'
error message. Please verify that the above code is correct and repost if necessary.

Sign in to comment.

Answers (0)

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!