フィルターのクリア

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 Center および File ExchangeSolver 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