There is an error in call the function file

2 次查看(过去 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
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
Walter Roberson 2023-6-4
fluxfunction([8 1 5],[9 3 -1])
Not enough input arguments.

Error in solution>f (line 7)
V = exp(-t)*sin(pi*x)*(pi^2-1);

Error in solution>fluxfunction (line 4)
V = max(f(max(a,0)),f(min(b,0)));
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
Walter Roberson 2023-6-4
fluxfunction()
Not enough input arguments.

Error in solution>fluxfunction (line 4)
V = max(f(max(a,0)),f(min(b,0)));
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 CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by