"Not enough input arguments" error

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by