why this program showing error like undefined variable.?..one day before same program was giving results but now it os showing error.please help

Pc=620*10^6
Pa=62*10^9
Ps=1*10^9
r=10
d=1:10:1000
s=(d./r)
s1=s
w1=4.3
E0=8.85*10^-12
Eb=6.830890.*(w1.^(3/2))
A1=d.^2
B1=(d./d0).^(1/3)
l=(Eb./B1)
m= (2.*Pc./E0).^(1/2)
n=(8.*Pa./(E0.*(1+s).^4)).^(1/2)
x1=min(m,n)
Es=min(x1,l)
h=8
l1= 0.5.*E0.*l.^2.*10^18
n1=(4.*Pa)./((1+(s)).^4)
y1=min(l1,Pa)
y2=min(y1,n1)
if s1<=2
e1=1
elseif s1>=2
e1= (s+2)./4
elseif s1>2;
e1=(d./r)./4
end
x1=e1;
A1=d.^2
u=e1.*y2
A2=(A1.*Ps)./u
A=(A1+A2)
x2=(d+h)
Vw=(d.*A1)./(x2.*A)
uw=(u.*Vw)
plot(d,uw)

5 commentaires

Hi, In calculating B1=(d./d0).^(1/3) you have not initialized the value of d0. Also in the if-elseif control you have not defined the value of e1, if none of the conditions are satisfied.To fix that you can initialize e1 or include else e1=0(or some other value); after the elseif statement elseif s1>2.
Pc=620*10^6 Pa=62*10^9 Ps=1*10^9 r=10
d0=0.4 d=1:10:100 d1=100:100:10000000 s=(d./r) k=(s+2)./4 k1=s./4 s1=s w1=4.3 E0=8.85*10^-12 Eb=6.830890.*(w1.^(3/2)) A1=d.^2 B1=(d./d0).^(1/3)
l=(Eb./B1) m= (2.*Pc./E0).^(1/2) n=(8.*Pa./(E0.*(1+s).^4)).^(1/2) x1=min(m,n) Es=min(x1,l) h=8 l1= 0.5.*E0.*l.^2.*10^18 n1=(4.*Pa)./((1+(s)).^4) y1=min(l1,Pa) y2=min(y1,n1)
if s1<=2 e1=1 elseif s1>=2 e1= k elseif s1>2; e1=k1 else
end
x1=e1; A1=d.^2 u=e1.*y2 A2=(A1.*Ps)./u A=(A1+A2) x2=(d+h) Vw=(d.*A1)./(x2.*A) uw=(u.*Vw)
plot(d,uw)
still showing error
@an: Formatted code is easier to read. And please post a copy of the error message, most of all the line, which causes the error. Then we do not have to guess. But in addition, that error message tells you, which variable has not been defined. Then it is easy to search in the code by your own and add the required definition of the variable.
The shown code seems to be a script and not a function. Then the variables, which are missing today, have been defined before the script yesterday, either in another script or in the command window. Prefer using functions to avoid such problems.
As pointed out above by RAGHAVENDRA, there is no assignment for e1 in the final else
else
e1 = 0; % add some statement to assign a value
end
I strongly suspect that your code jumps right into the else, no value for e1 is assigned, which results in the error message.
yes, the code directly jumps to else statement it is not computing the if else values.
how to assign value for e1, e1 is a variable only.

Connectez-vous pour commenter.

 Réponse acceptée

My answer to why it worked one day and not another would be pasted code is a script. The issue with scripts is that if you do not clear the workspace before running it multiple times value may not be cleared. So if it is defined during debugging or in a previous iteration it will still be defined until you close down matlab or clear the workspace.

Plus de réponses (0)

Catégories

En savoir plus sur Performance and Memory dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by