There is an error in call the function file
Show older comments
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 Comment
KALYAN ACHARJYA
on 4 Jun 2023
f in the function?
Answers (1)
Star Strider
on 4 Jun 2023
0 votes
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
on 4 Jun 2023
For once that is not the case. The error message is inside f, which is being sucessfully passed something -- but f expects at least two parameters. Probably f expects both x and t
Star Strider
on 4 Jun 2023
I was thinking that in the ‘V’ assignment (that’s throwing the error), ‘f’ is being passed ‘max(a,0)’ and ‘min(b,0)’ so that if ‘a’ and ‘b’ don’t exist, those arguments don’t exist and ‘f’ (that apparently takes only one argument) throws the error (although I would expect max or min to throw it instead in that instance).
I was actually able to find that reference as the MATLAB code for Shape-from-Shading, with the same function names although the code is quite different. I don’t know what’s going on with this.
Walter Roberson
on 4 Jun 2023
f would not get invoked until all of the parameters to the call to f are ready -- so if the problem were that a or b were missing, that would be detected as an error in fuxfunction not as an error in f
You can only get error reports with line numbers inside f if f has started execution.
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
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.
Categories
Find more on Debugging and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!