# "Not enough input arguments" error

1 回表示 (過去 30 日間)
Josie 2023 年 11 月 20 日
コメント済み: Josie 2023 年 11 月 20 日
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 件のコメント2 件の古いコメントを表示2 件の古いコメントを非表示
Dyuman Joshi 2023 年 11 月 20 日

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 2023 年 11 月 20 日
Ah ok I get it now thank you!

サインインしてコメントする。

### 採用された回答

Sulaymon Eshkabilov 2023 年 11 月 20 日
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

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

### Community Treasure Hunt

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

Start Hunting!

Translated by