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.

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)

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.
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

I changed it to: F=inf; R=inf; while F>1 && R>1
That didn't work unfortunately
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?
It stops at the first line after the first end, whatever that means :/
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;
Wtotal=40030; %tractor weight (lbs)
%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)
Sr= 37; %static loaded radius of rear tire (in)
Wsar=22575; %the static rear axle load
deltar= (Dr/2)-Sr;
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)
Sf= 28.4; %static loaded radius of rear tire (in)
Wsaf=17455; %the static rear axle load
deltaf= ((Df/2)-Sf);
rear_t=6; % # of rear tires
c=(Wsaf*L)/Wtotal; %center of mass calculation, FBD eq
for i=1:length(s)
F=inf;
R=inf;
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
Px=NTF+NTR;
Py=(Px/sin(deg2rad(72)))*sin(deg2rad(18));
P=sqrt(((Px).^2)+((Py).^2));
Normf=((Wdf*L)-(P*(dbh*cos(deg2rad(18))+d*sin(deg2rad(18)))))/L; %Normal Force on Front Axle
Normr=Wdf+Wdr+(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_new=Normf; %Assigning calculated dynamic weights to begin loop again
Wdr_new=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

Sign in to comment.

Categories

Asked:

on 9 Apr 2016

Answered:

on 10 Apr 2016

Community Treasure Hunt

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

Start Hunting!