MATLAB: Unspecified Error in Function

MATLABuser defined function error

The following code shows an error in lines 21 and 41 where the function "thetaFun" is called and defined. Guidance would be much appreciated.
function FredlundXing
clc
% Parameters:
thetaS=0.394; %[-] saturated water content
a=5.041; %[kPa] FP, tied to AEV
n=8.5093; %[-] FP, tied to fluid drain rate after AEV
m=0.7; %[-] FP, tied to residual WC
psiL=-10^6; %[kPa] Max possibe soil suction
psir=-2000; %[kPa] residual suction
% Create pressure head vector for plotting
psi=linspace(-1000000,0,10000);
% Calculate correction factor C(psi)
C=CFun(psi,psir,psiL);
% Calculate water content
theta=thetaFun(psi,thetaS,a,n,m);
% Plot C-psi
subplot(3,1,2)
semilogx(abs(psi),C)
ylabel('Correction [-]')
xlabel('Pressure head [kPa]')
% Correction factor function
function [C]=CFun(psi,psir,psiL)
Cn=(1+(psi/psir));
Cd=(1+(psiL/psir));
C=1-(log(Cn)/log(Cd));
% Fredlund & Xing (1994) theta-psi relation
function [theta]=thetaFun(psi,thetaS,a,n,m)
Cn=(1+(psi/psir));
Cd=(1+(psiL/psir));
C=1-(log(Cn)/log(Cd));
Td=log(exp(1)+(psi./a).^n);
theta=C.*((thetaS)/((Td).^m))

Best Answer

Look at how thetafun is define:
function [theta]=thetaFun(psi,thetaS,a,n,m)
yet you use psir inside it. How do you expect psir to have a value when you don't pass it in? Define it like this:
function [theta]=thetaFun(psi, psir, thetaS,a,n,m)
and call it like this:
theta=thetaFun(psi, psir, thetaS,a,n,m);
Related Question