필터 지우기
필터 지우기

"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 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