"Not enough input arguments" error

1 回表示 (過去 30 日間)
Josie
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 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 11 月 20 日
編集済み: 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
Josie 2023 年 11 月 20 日
Ah ok I get it now thank you!

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

採用された回答

Sulaymon Eshkabilov
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

その他の回答 (0 件)

カテゴリ

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