Clear Filters
Clear Filters

"Not enough input arguments" error

1 view (last 30 days)
Josie
Josie on 20 Nov 2023
Commented: Josie on 20 Nov 2023
I keep getting the "Not enough input arguments" error in the following code and I was wondering if someone can help me fix?
function backward_heat(x,u0)
% Solves the heat equation by backward difference method and plots the
% result; x - (pre-calculated) array of grid points
% in x, u0 - (pre-calculated) initial condition at grid points
N=length(x)-1;
if (N+1)~=length(u0)
error('Dimensions of x and u0 must agree')
end
h=(x(N+1)-x(1))/N;
tau=T/M; gamma=tau/h^2
w=zeros(N+1,M+1);
% grid points
t=(0:M)*tau;
% initial condition
w(:,1)=u0;
% solving the tridiagonal system by the double-sweep method
alpha=zeros(1,N);
beta=zeros(1,N);
for m=2:(M+1)
for k=1:(N-1)
alpha(k+1)=gamma/(1+gamma*(2-alpha(k)));
beta(k+1)=(beta(k)*gamma+w(k+1,m-1))/(1+gamma*(2-alpha(k)));
end
for k=(N+1):(-1):3
w(k-1,m)=alpha(k-1)*w(k,m)+beta(k-1);
end
end
% surface plot of u(x,t)
w=w';
surf(x,t,w);
  4 Comments
Dyuman Joshi
Dyuman Joshi on 20 Nov 2023
Edited: Dyuman Joshi on 20 Nov 2023
What is the assignment?
"Would you be able to explain what I need to do to get rid of the error please."
I did - You need to provide the values when you call the function. For your case, those would be x and u0.
Example - Let's take the tan function. You want to find the tan of something, but if you do not specify the value of something, how will MATLAB calculate the output?
So, it will give an error as follows -
tan
Error using tan
Not enough input arguments.
Josie
Josie on 20 Nov 2023
Ah ok I get it now thank you!

Sign in to comment.

Accepted Answer

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 20 Nov 2023
Variables T and M are also not specified. See how it can be executed:
x = 0:13;
u0 = ones(size(x));
backward_heat(x,u0)
gamma = 5
function backward_heat(x,u0)
% Solves the heat equation by backward difference method and plots the
% result; x - (pre-calculated) array of grid points
% in x, u0 - (pre-calculated) initial condition at grid points
N=length(x)-1;
if (N+1)~=length(u0)
error('Dimensions of x and u0 must agree')
end
h=(x(N+1)-x(1))/N;
T = 10; M = 2; % Some values are assigned for T and M
tau=T/M; gamma=tau/h^2
w=zeros(N+1,M+1);
% grid points
t=(0:M)*tau;
% initial condition
w(:,1)=u0;
% solving the tridiagonal system by the double-sweep method
alpha=zeros(1,N);
beta=zeros(1,N);
for m=2:(M+1)
for k=1:(N-1)
alpha(k+1)=gamma/(1+gamma*(2-alpha(k)));
beta(k+1)=(beta(k)*gamma+w(k+1,m-1))/(1+gamma*(2-alpha(k)));
end
for k=(N+1):(-1):3
w(k-1,m)=alpha(k-1)*w(k,m)+beta(k-1);
end
end
% surface plot of u(x,t)
w=w';
surf(x,t,w);
end

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!