Not enough input arguments.
Show older comments

Not enough input arguments.
Error in BDF>@(t,y)mu*(y-cos(t))-sin(t) (line 7)
f_m = @(t,y) mu*(y-cos(t))-sin(t);
Error in BDF (line 14)
y_m(i)=(4.*y_m(i-1)-y_m(i-2))/3+(2/3).*h*(3*f_m(t(i)))
%% Backward Difference Formula Method %%
clc; clear all;
h=0.01;
t=0:h:1;
n=numel(t);
mu = 20;
f_m = @(t,y) mu*(y-cos(t))-sin(t);
exact = @(t) exp(mu*t)+cos(t);
%initials%
y_m(1)=exact(0);
y_m(2)=exact(h);
%Adam-Bashforth method%
for i=3:n
y_m(i)=(4.*y_m(i-1)-y_m(i-2))/3+(2/3).*h*(3*f_m(t(i)))
end
plot(t, exact(t));
hold
plot(t,y);
%plot(t,y,'-o');
legend('Exact Solution','BDF Solution')
xlabel('t')
ylabel('y')
title('When h = 0.01 and µ=20')
6 Comments
Hazel Can
on 25 May 2022
The BDF method gives the following equation for y(n):
y(n) = ( 4*y(n-1)-y(n-2) )/3 + 2*h/3* ( mu*( y(n) - cos(t(n)) ) - sin(t(n)) )
Solve this equation for y(n) and update y_m(i) in the loop accordingly.
Hazel Can
on 26 May 2022
If I write
x = ( 4*y(n-1)-y(n-2) )/3 + 2*h/3* ( mu*( x - cos(t(n)) ) - sin(t(n)) )
and say to solve for x, do you know how to proceed ?
After doing this, your loop looks like
for i=3:n
y_m(i) = the expression you got for x (with y(...) replaced by y_m(...))
end
Hazel Can
on 29 May 2022
Hazel Can
on 29 May 2022
Answers (2)
%% Backward Difference Formula Method %%
clc; clear all;
h=0.01;
t=0:h:1;
n=numel(t);
mu = 20;
f_m = @(t,y) mu*(y-cos(t))-sin(t);
exact = @(t) exp(mu*t)+cos(t);
%initials%
y_m(1)=exact(0);
y_m(2)=exact(h);
%Adam-Bashforth method%
for i=3:n
fun = @(x) x - (4*y_m(i-1)-y_m(i-2))/3 - 2*h/3*f_m(t(i), x);
y_m(i)=fzero(fun, y_m(i-1));
end
plot(t, exact(t)); hold
plot(t,y_m);
%plot(t,y,'-o');
legend('Exact Solution','BDF Solution')
xlabel('t')
ylabel('y')
title('When h = 0.01 and µ=20')
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!