Can anyone help me figure out where the error is? It says "undefined function or variable NormF" when I run it but I can't figure it out.
Show older comments
clear all
close all
format long g
clc
%Tire Performance Analysis
%Garrett Froula
%BsE 411
ci=174.0453; %Cone index in psi
t=18*(pi/180); %18 degree angle
dbh=20.5; %drawbar height (in)
s=.01:.001:.2; %slip range 1-20 increments of .1
L=118.9; %wheel base length (in)
d=1.75*dbh;
%Rear Tire Specifications
hr=15.1; %rear tire section height (in)
br=19; %unloaded tire section width rear (in)
Dr=80.8; %unloaded overall diameter (in)
SLRR= 37; %static loaded radius of rear tire (in)
Wsar=22575; %the static rear axle load
deltar= ((80.8/2)-27);
front_t=4; % # of front tires
%Front Tire Specifications
bf=16.5; %unloaded tire section width (in)
hf=14.06; %front tire section height (in)
Df=62.6; %unloaded overall diameter (in)
Sr= 28.4; %static loaded radius of rear tire (in)
Wsaf=17455; %the static rear axle load
deltaf= ((Df/2)-Sr);
rear_t=6; % # of rear tires
c=((Wsaf*L)+(Wsar*0))/(Wsaf+Wsar); %center of mass calculation, FBD eq
for i=1:length(s)
F=0;
R=0;
while F>1 && R>1
Wstf=Wsaf/front_t; %static front tire weight
Wstr=Wsar/rear_t; %statis rear tire weight
Wdf=Wstf;
Wdr=Wstr;
Bnf=((ci*bf*Df)/Wdf)*((1+5*(deltaf/hf))/(1+3*(bf/Df))); %Bn for Front
Bnr=((ci*bf*Dr)/Wdr)*((1+5*(deltar/hr))/(1+3*(br/Dr))); %Bn for Rear
NTf=Wdf*(.88*(1-exp(-.1*Bnf))*(1-exp(-7.5*s))-(1/Bnf)-((.5*s)/sqrt(Bnf))); %Net Traction Front tires
NTr=Wdr*(.88*(1-exp(-.1*Bnr))*(1-exp(-7.5*s))-(1/Bnr)-((.5*s)/sqrt(Bnr))); %Net Traction Rear tires
NTF= NTf*front_t; %NT front axle for FBD
NTR= NTr*rear_t; %NT rear axle for FBD
P=(NTF+NTR)/cos(deg2rad(18));
NormF=((Wf*L)-(P*(dbh*cos(deg2rad(18))+d*sin(deg2rad(18)))))/L; %Normal Force on Front Axle
NormR=Wf+Wr+(P*sin(deg2rad(18)))-NormF; %Normal Force on Rear Axle
F=abs(NormF-Wsaf); %Front Axle error calculation
R=abs(NormR-Wsaf); %Rear Axle error calculation
Wdf=NormF; %Assigning calculated dynamic weights to begin loop again
Wdr=NormR;
end
Nf=NormF/front_t; %dynamic weights per front tire
Nr=NormR/rear_t; %dynamic weights per rear tire
GTf=Wdf*((.88*(1-exp(-.1*Bnf))*(1-exp(-7.5*s)))+.04); %Gross Traction front
GTr=Wdr*((.88*(1-exp(-.1*Bnr))*(1-exp(-7.5*s)))+.04); %Gross Traction rear
TEf=(1-s)*(NTF/GTf); %Tractive efficiency front axle
TEr=(1-s)*(NTR/GTr); %Tractive efficiency rear axle
end
Answers (2)
Walter Roberson
on 10 Apr 2016
1 vote
You need R2015b or later, or a File Exchange contribution to define deg2rad . Or just write it yourself, as it is very simple.
You define NTf and NTr in terms of s, which you have defined as a vector. That makes all of the expressions that follow inside the while vectors (because you use those terms), including F and R. So after one iteration, F and R are both vectors, and your while F>1 && R>1 will be computing F>1 as a vector of results, and R>1 as a vector of results. But you cannot use && to join vectors of logical results, so you will get an error message. If you want F and R to be vectors at that point, then you need to switch from && to & .
Remember that when you have an if or while that is testing a vector (or array) that the condition is considered to be true only if all elements of the vector are non-zero, so after you switch to & the while will continue only until there is at least one spot, K, where (F(K)>1 & R(K)>1) is not true. So, as soon as there is one s location where either F or R (or both) are within tolerance, the while will end.
John D'Errico
on 9 Apr 2016
Edited: John D'Errico
on 9 Apr 2016
LEARN TO USE THE DEBUGGER!!!!!!!
Actually here, the answer is simple enough that it is not necessary, iF you think about the error message.
NormF is not defined. That means what it says. When you hit the line where normF is needed, it was undefined. So, lets look at your code.
I'll just show the important lines.
for i=1:length(s) F=0; R=0;
while F>1 && R>1
...
NormF=((Wf*L)-(P*(dbh*cos(deg2rad(18))+d*sin(deg2rad(18)))))/L; %Normal Force on Front Axle
...
end
Nf=NormF/front_t; %dynamic weights per front tire
Ok, so you compute the variable NormF INSIDE a while block. How can NormF be not defined? LOOK AT THE TEST in the wile statement.
while F>1 && ...
But what is F? Just before that, you set F to be zero! Is 0>1? The last time I checked, that is false. So the while loop did not execute at all, but then NormF was used after it drops through. Therefore, NormF never got assigned.
LEARN TO USE THE DEBUGGER. If you cannot do that, then learn to read the error message. Think about what the message is telling you. The MATLAB gods put error messages there for your benefit.
7 Comments
Garrett
on 9 Apr 2016
Walter Roberson
on 9 Apr 2016
initialize F to infinity.
Garrett
on 9 Apr 2016
Walter Roberson
on 10 Apr 2016
If you put in a breakpoint and single-step then does the debugger indicate that you have entered the while loop or does it indicate that it immediately skipped around it?
Garrett
on 10 Apr 2016
Walter Roberson
on 10 Apr 2016
Please show the current code.
Garrett
on 10 Apr 2016
Edited: Walter Roberson
on 10 Apr 2016
Categories
Find more on Wheels and Tires 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!