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

Réponses (1)

Adam
Adam le 6 Juil 2016

0 votes

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 commentaires

yeah when i input h0,hL,L, and n i still get this error
Adam
Adam le 6 Juil 2016
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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Physics dans Centre d'aide et File Exchange

Commenté :

le 7 Juil 2016

Community Treasure Hunt

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

Start Hunting!

Translated by