필터 지우기
필터 지우기

Undefined function or variable

조회 수: 1 (최근 30일)
Uday padidela
Uday padidela 2014년 9월 24일
댓글: Uday padidela 2014년 9월 24일
Hello All,
I get this error
Undefined function or variable "uw".
Error in myoz>elj (line 292)
ua=exp(-beta*(uw + cb));
Error in myoz (line 66)
U11=elj(r,sig11,eps11,beta,Lb,q1,q1);
How to solve it? Can anyone please help me to solve it?
This is my code
function [h,c]=myoz
global L U rho iopt
iopt = 0; % Hyper-netted Chain
n=8193;
eps11=1.0; eps12=0.7; eps22=0.5;
sig11=10.0; sig12=6.0; sig22=1.0;
q1=-2.0;q2=+1.0;
rho1= 0.25*10^(-4);
rho2=(-rho1*q1)/q2;
beta=0.40093;
Lb= 0.0036069;
dx = sig11/300; L = (n-1)*dx; r=0:dx:L; r=r';
dt= pi./L;
rho=[rho1',rho2']';
%U=elj(r,sigma,epsilon,beta);
U11=elj(r,sig11,eps11,beta,Lb,q1,q1);
U12=elj(r,sig12,eps12,beta,Lb,q1,q2);
U22=elj(r,sig22,eps22,beta,Lb,q2,q2);
U=[U11',U12',U22']';
tol=[1.d-8,1.d-8];
x=zeros(6*n,1);
parms=[40,80,-0.9];
[sol, it_hist, ierr] = nsoli(x,'oz',tol);
%
%%Unpack h and c.
%
h11=sol(1:n);h12=sol(n+1:2*n); h22=sol(2*n+1:3*n);
c11=sol(3*n+1:4*n); c12=sol(4*n+1:5*n); c22=sol(5*n+1:6*n);
g11= h11+1; g12= h12+1; g22= h22+1;
cd=cdirect(c12,c22);
ceff=c11+cd;
if h11~=0.0
veff = h11-ceff-log(1.0+h11);
else
veff=0.0;
end
h111= (exp(-veff+h11-ceff))-1;
function u= elj(r,sigma,epsilon,beta,Lb,q1,q2)
n2=length(r);
ra=r(2:n2);
r12=(sigma./ra).^12; r6=(sigma./ra).^6;
%cb =((q1*q2)./(4*pi*epsilon0*ra*0.59616));
%u = uwca+cb;
cb = ((Lb*q1*q2)./(beta*ra));
uj= 4*epsilon*(r12-r6);
us=0.25*epsilon;
if ra <= 1.12246*sigma
uw = uj+us;
else
ua=exp(-beta*(uw + cb));
end
u=[0,ua']';

채택된 답변

Adam
Adam 2014년 9월 24일
'uw' is defined in an if statement, but used in the else part of the same if statement where it is guaranteed not to be defined.
  댓글 수: 1
Uday padidela
Uday padidela 2014년 9월 24일
Thank you Adam.. Yeah i solved it..Thank you for your time.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

dpb
dpb 2014년 9월 24일
function u= elj(r,sigma,epsilon,beta,Lb,q1,q2)
...
if ra <= 1.12246*sigma
uw = uj+us;
else
ua=exp(-beta*(uw + cb));
end
There's no path to have uw defined in the function if the else clause is taken...only if the condition is true will there be a value for uw defined.
  댓글 수: 1
Uday padidela
Uday padidela 2014년 9월 24일
Thank you.. I have solved it.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by