Clear Filters
Clear Filters

There is an error in call the function file

1 view (last 30 days)
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

Answers (1)

Star Strider
Star Strider on 4 Jun 2023
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 Comments
Walter Roberson
Walter Roberson on 4 Jun 2023
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 on 4 Jun 2023
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!