Why do I get the error (not enough input arguments) when run the script about 2nd-order Adams-Bashforth (Explicit Method)?

Greetings!
Can someone help me review my code about solve ODE-IVPs using 2nd-order Adams-Bashforth (Explicit Method)? Because I faced error (Not enough input arguments) when I run the script.
Thanks in advance
function [t,y] = AB2(fun,tspan,y0,y1,y2,N)
a = tspan(1);
b = tspan(2);
h = (b-a)/N;
t = zeros(N+1,1);
y = zeros(N+1,1);
t(1) = a; y(1) = y0;
t(2) = a+h; y(2) = y1;
for i = 2:N
t(i+1) = t(i) + h;
Fi = fun(t(i),y(i));
Fi1 = fun(t(i-1),y(i-1));
y(i+1) = y(i) + h/2*(3*Fi - Fi1);
end
%% 2nd-order Adams-Bashforh Solution
fun = @(t,y) ((1+4*t)*((y)^1/2)); %Function f(t,y)
y0 = 1; %Initial Condition
tspan = [0,1];
N = 4; %Number of subintervals, h = (b-a)/N
%% Initial Values
h = (tspan(2) - tspan(1))/N;
exactY = @(t) @(t) (((3*t)/2)+3*t.^2).^(2/3);
t1 = tspan(1) + h; y1 = exactY(t1);
t2 = tspan(1) + 2*h; y2 = exactY(t2);
[t2,Y2] = AB2(fun,tspan,y0,y1,N);
%% Display Solution
Y = exactY(t2);
disp('-----------------------------');
disp('t_i y(t_i) AB2 Error')
disp('-----------------------------');
formatSpec = '%.2f %.5f %.5f %.5f\n';
fprintf(formatSpec,[t2';Y';Y2';abs(Y'-Y2')])

Answers (1)

%%2nd-order Adams-Bashforh Solution
move everything from that line onwards to a new file, and execute that other file.

3 Comments

It still error. When I moved the everything on
%%2nd-order Adams-Bashforh Solution
to a new file, and execute that other file. It showed
Unrecognized function or variable 'tspan'.
Error in HW2Number1AB2OK (line 7)
h = (tspan(2) - tspan(1))/N;
function [t,y] = AB2(fun,tspan,y0,y1,y2,N)
[t2,Y2] = AB2(fun,tspan,y0,y1,N);
Do you see that the function needs one more input parameter than you supply in the call ?

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Release

R2021b

Community Treasure Hunt

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

Start Hunting!