i am geeting an error as "??? Input argument "int_H" is undefined.

I post here the function and the line that gives me this error: gas_species_balance.m file
function [C_species] = gas_species_balance(Gen_species, ...
C_species,int_H,int_r, A_r,A_z, v_r,v_z,vol,dt,ep)
relpar_species =1.0;
err_species=1.0;
iter_species=0;
while err_species>10^-3
iter_species=iter_species+1;
if iter_species>100
break;
end
for i=2:int_H+1
for j=1:int_r
aP(i,j)=0.;
source(i,j)=0.;
aPrev=ep(i,j)*vol(i,j)/dt;
aP(i,j)=aP(i,j)+aPrev(i,j);

3 Comments

How are you invoking the function?
@vandana: I've formatted your code. Please use the "{} Code" button. Thanks.
Hi Jan Simon, I am not getting it.. I have given the full code below... please help

Sign in to comment.

 Accepted Answer

There are several missing end statements in the code.
10^-3 is an expensive power operation, while 1e-3 is a cheap constant.
Please post (and read) the complete error message. The offending line might contain a call like gas_species_balance(a, b), while the later input arguments are missing.

3 Comments

Hi...
error is coming at line " for i=1:int_H"
but still I am giving the full code now..
function [C_species] = gas_species_balance(Gen_species,C_species,int_H,int_r,A_r,A_z,v_r,v_z,vol,dt,ep)
relpar_species =1.0;
err_species=1.0;
iter_species=0;
while err_species>10^-3
iter_species=iter_species+1;
if iter_species>100
break;
end
for i=2:int_H+1
for j=1:int_r
aP(i,j)=0.;
source(i,j)=0.;
aPrev=ep(i,j)*vol(i,j)/dt;
aP(i,j)=aP(i,j)+aPrev(i,j);
if i==int_H+1
source(i-1,j)= v_z(i,j)*A_z(i,j)*C_species(i,j)+Gen_species(i,j)*vol(i,j);
else
source(i-1,j)=Gen_g_species(i,j)*vol(i,j);
end
if j==1
aE(i,j)=0.0;
else
aE(i,j)=A_r(i,j-1)*max(0,v_r(i,j-1));
aP(i,j)=aP(i,j)+A_r(i,j-1)*max(0,v_r(i,j-1));
end
aW(i,j)=A_r(i,j)*max(0,v_r(i,j));
aP(i,j)=aP(i,j)+A_r(i,j)*max(0,v_r(i,j));
aN(i,j)=A_z(i-1,j)*max(0,v_z(i-1,j));
aP(i,j)=aP(i,j)+A_z(i-1,j)*max(0,v_z(i-1,j));
aS(i,j)=A_z(i,j)*max(0,v_z(i,j));
aP(i,j)=aP(i,j)+A_z(i,j)*max(0,v_z(i,j));
end
end
for j=1:int_r
for i=2:int_H+1
if j==1
source(i-1,j)=source(i-1,j)+aPrev(i-1,j)*C_species(i,j)+aW(i-1,j)*C_species(i,j+1);
elseif j==int_r
source(i-1,j)=source(i-1,j)+aPrev(i-1,j)*C_species(i,j)+aE(i-1,j)*C_species(i,j-1);
else
source(i,j)=source(i-1,j)+aPrev(i-1,j)*C_species(i,j)+aE(i-1,j)*C_species(i,j-1)+aW(i-1,j)*C_species(i,j+1);
end
end
C_species_new1(:,j)= tridi(-aS(:,j), aP(:,j),-aN(:,j),source(:,j),int_H);
end
for i=2:int_H
for j=1:int_r
C_species_new(i,j)=C_species_new1(i-1,j);
end
end
err_species = abs(C_species_new(i,j)-C_species(i,j))/(1.+abs(C_species_new(i,j)));
for i=2:int_H+1
for j=1:int_r
C_species(i,j) = relpar_species*C_species_new(i,j) + (1-relpar_species)*C_species(i,j);
end
end
end
Error "?? Input argument "int_H" is undefined.
Error in ==> gas_species_balance at 13
for i=2:int_H+1
"
please help
You have not shown how you are invoking the function. Show the line of code that calls gas_species_balance
Hi
code is giving error at the line #13 which I am writing here for i=2:int_H+1 for j=1:int_r
I am invoking the function as in different .m file actuly C_species_CO2=gas_species_balance(Gen_CO2_species,C_species_CO2,A_r,A_z,v_r,v_z,int_r,int_H,vol,dt,ep);

Sign in to comment.

More Answers (1)

You have to evoke the function with argument in the same order as you have defined the function. You define the function with H_int as the third argument, but call it with H_int as the 8th argument. Matlab does not match the arguments based on the names of the variables, it just matches the order.
BTW, 11 is quite a high number of arguments. You may want to reduce the number by aggregating variables, like
A(:,:,1) = A_r; A(:,:,2) = A_z;
v(1,:) = v_r; v(2,:) = v_z;
params = [nt_r,int_H,vol,dt,ep];
function(Gen_CO2_species,C_species_CO2, A, v, params)

1 Comment

hi I have evoked the function with arguments in same order as defined function but still facing the same error. I am getting the error at "for" loop only , code is not going upto the line where I am evoking the function

Sign in to comment.

Categories

Asked:

on 8 Jul 2015

Commented:

on 10 Jul 2015

Community Treasure Hunt

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

Start Hunting!