There is an error in call the function file
조회 수: 5 (최근 30일)
이전 댓글 표시
function V = fluxfunction(a,b)
% Godunov
V = max(f(max(a,0)),f(min(b,0)));
end
%%%%%%%%%%%%%%%%%%
% Godunov Scheme
% ut + (u^2/2)x = eps*uxx;
x0 = 0;
xf = 5;
N = 100;
h = (xf-x0)/N;
eps = 0.01;
delt = 0.5*h;
lambda = delt/h;
mu = delt/(h^2);
t0 = 0;
tf = 5;
x = zeros(N-1,1);
u0 = zeros(N-1,1);
for j=1:N-1
x(j) = x0+j*h;
if(x(j) < 1)
u0(j) = sin(pi*x(j));
end
if(x(j) > 1)
u0(j) = 0;
end
end
M = fix((tf-t0)/delt);
unew = zeros(N-1,1);
t = t0;
for k=1:M
unew(1) = u0(1) - lambda*(fluxfunction(u0(1),u0(2)) - fluxfunction(0,u0(1))) + mu*eps*(u0(2) - 2*u0(1) + 0);
unew(N-1) = u0(N-1) - lambda*(fluxfunction(u0(N-1),0) - fluxfunction(u0(N-2),u0(N-1))) + mu*eps*(u0(N-2) - 2*u0(N-1) + 0);
for j=2:N-2
unew(j) = u0(j) - lambda*(fluxfunction(u0(j),u0(j+1)) - fluxfunction(u0(j-1),u0(j))) + mu*eps*(u0(j+1) - 2*u0(j) + u0(j-1));
end
plot(x,unew)
title('Godunov Scheme');
ylim([0,1]);
pause(0.01);
u0 = unew;
t = t+delt;
end
ugod = unew;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Error %%%%%%%%%%%%%%%%%%%%%
Not enough input arguments.
Error in f (line 3)
V = exp(-t)*sin(pi*x)*(pi^2-1);
Error in fluxfunction
V = max(f(max(a,0)),f(min(b,0)));
Error in Godnov
답변 (1개)
Star Strider
2023년 6월 4일
You need to call ‘fluxfunction’ from a script with specific values for ‘a’ and ‘b’ that already existing in the script workspace. You cannot run it by clicking on the green ‘Run’ arrow in the Editor or by running it from the Command Window as you would a script, without supplying apppropriate values for the arguments.
댓글 수: 5
Walter Roberson
2023년 6월 4일
fluxfunction([8 1 5],[9 3 -1])
function V = fluxfunction(a,b)
V = max(f(max(a,0)),f(min(b,0)));
end
function V = f(x,t)
V = exp(-t)*sin(pi*x)*(pi^2-1);
end
Walter Roberson
2023년 6월 4일
fluxfunction()
function V = fluxfunction(a,b)
V = max(f(max(a,0)),f(min(b,0)));
end
function V = f(x,t)
V = exp(-t)*sin(pi*x)*(pi^2-1);
end
Observe that if not enough inputs are passed to fuxfunction so the parameters to f cannot be evaluated, then the error is reported in fluxfunction, whereas if enough parameters are passed to fluxfunction but not enough are passed to f, then the error is reported in f.
참고 항목
카테고리
Help Center 및 File Exchange에서 Debugging and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!