MATLAB: Please explain what this error is…

function errormatlab function

[Mistakenly put Q? in Title moved to Body by dpb]
Hi, I'm very new to MATLAB and I am having some trouble. Lots of people have had the same problem but nobody seems to be able to explain or solve it in plain English. Could somebody please explain what this error is and how to fix it? I have a simpl…
function [eq1,eq2,eq]= Myfun(a,b)
m0=9.1094e-31;
me=.7*m0;
q=1.60218e-19;
k=1.38064852e-23;
Tc=300;%kelvin
KT=k*Tc;
h_plank=6.626069572929e-34;
hbar=h_plank/(2*pi);
c=3e8;
omega=6.8e-6;
V=1*q;
Ts=5678;
KT2=k*Ts;
ph=h_plank*pi;
hc=h_plank^3*c^2;
filename='am15.txt';
As=importdata(filename);
lambda=As(1,:)*1e-9;
x=h_plank*c./lambda; % x is E
% M(1) is T_H and M(2) is delta_mu
Delta_E=0.01;
Ext_E=1.7;
for iii=1:length(x)
if (Ext_E/2-Delta_E/2) < x(iii) < (Ext_E/2+Delta_E/2)
% if x(iii) >= (Ext_E/2-Delta_E/2) && x(iii) <= (Ext_E/2+Delta_E/2)
tau=1;
elseif x(iii) >= (Ext_E/2+Delta_E/2) || x(iii) <= (Ext_E/2-Delta_E/2)
tau=0;
end
end
eq1=trapz(x,tau*(me*k*a/ph)*log10(1+exp(-(x-b/2)./k*a)));
eq2=trapz(x,tau*(me*KT/ph)*log10(1+exp(-(x-V/2)./KT)));
eq3=trapz(x,(2*omega/hc)*(x.^2./(exp(x/KT2)-1)));
eq4=trapz(x,(2*pi/hc)*(x.^2./(exp((x-b/2)/k*a)-1)));
eq1=(1/(pi*hbar))*(eq1-eq2)-eq3+eq4;
eq11=(trapz(x,tau*(me*k*a/ph)*(x+a*k-b/2).*log10(1+exp(-(x-b/2)./k*a))));
eq22=trapz(x,tau*(me*KT/ph)*((x+KT-V/2)).*log10(1+exp(-(x-V/2)./KT)));
eq33=trapz(x,(2*omega/hc)*(x.^3./(exp(x/KT2)-1)));
eq44=trapz(x,(2*pi/hc)*(x.^3./(exp((x-b/2)./k*a)-1)));
eq2=(1/(pi*hbar))*(eq11-eq22)-eq33+eq44;
eq=[eq1 eq2];
end
when I run this program that matlab shows this error
>> Myfun
Not enough input arguments.
Error in Myfun (line 36)
eq1=trapz(x,tau*(me*k*a/ph)*log10(1+exp(-(x-b/2)./k*a)));

Best Answer

That's pretty straightforward problem and the error is quite simple to fix --
Your function definition line is
function [eq1,eq2,eq]= Myfun(a,b)
which says your function Myfun requires two input arguments, namely, variables you've named a, b (Not very informative of what they are, perhaps, but that's only an aid to the programmer to use meaningful variable names, MATLAB itself doesn't care).
You then tried to execute the function with the line
>> Myfun
without any input arguments passed for the two required arguments.
Line 36
eq1=trapz(x,tau*(me*k*a/ph)*log10(1+exp(-(x-b/2)./k*a)));
is the first line in the function that needs/references a and b and so throws the error that they're not defined because you didn't pass the required two arguments.
The fix is to call the function with two arguments for those two needed variables...whatever values they're supposed to have.
a=1; % make up some values for needed parameters
b=2;
Myfun(a,b)