error 'not enough input arguments" at line with dx..

function waterTableHt(h0,hL,L,n)
% Determine the height of the water table in a phreatic aquifer % input
% h0 = height of water table at one point
% hL = height of water table at another point
% L = length between the two points of known water table
% n = number of points for finite difference
%output
% no output, plot the height of the water table
% Initialization
dx=L/(n+1);
hmid =(h0 + hL)/2; %average height of the water table
N =.0001;
K =1;
MU =(N*dx^2)/(hmid*K);
A =zeros(n,n); %set up equations
b =zeros(n,1);
A(1,1)=2+MU; %first equation
A(1,2)=-1;
b(1)= MU + h0;
for i=2:n-1 %equations 2 through n-1
A(i,i-1)=-1;
A(i,i)=2+MU;
A(i,i+1)=-1;
b(i)=MU*hL;
end
A(n,n-1)=-1; %last equation
A(n,n)=2+MU;
b(n)=MU+hL;
h=A\b; %solve equations

답변 (1개)

Adam
Adam 2016년 7월 6일

0 개 추천

How are you calling your function? If you just click Run then you will obviously get this. That is a function that takes arguments so you need to call it from command line, a script or another function and pass in those arguments.

댓글 수: 3

yeah when i input h0,hL,L, and n i still get this error
Adam
Adam 2016년 7월 6일
How are you inputting them because that error doesn't make sense if you are passing the arguments in correctly?
the error has to be in the way you input the parameters to your function, because the following does not return any error:
h0=10
hL=11
L=100
n=280
dx=L/(n+1);
hmid =(h0 + hL)/2; %average height of the water table
N =.0001;
K =1;
MU =(N*dx^2)/(hmid*K);
A =zeros(n,n); %set up equations
b =zeros(n,1);
A(1,1)=2+MU; %first equation
A(1,2)=-1;
b(1)= MU + h0;
for i=2:n-1 %equations 2 through n-1
A(i,i-1)=-1;
A(i,i)=2+MU;
A(i,i+1)=-1;
b(i)=MU*hL;
end
A(n,n-1)=-1; %last equation
A(n,n)=2+MU;
b(n)=MU+hL;
h=A\b; %solve equations
ignore for a moment the people who tell you that you have to build functions. They tell so because if they see it useful, in the shape of functions it's easier to reuse, by them.
It's good practice, for you, to reach a working script before attempting to write a function of such length.
Regards
John BG

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

카테고리

도움말 센터File Exchange에서 Physics에 대해 자세히 알아보기

질문:

2016년 7월 6일

댓글:

2016년 7월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by