Not enough input arguments.
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
Jan
2022 年 5 月 25 日
f_m = @(t,y) mu*(y-cos(t))-sin(t);
f_m is a function with 2 inputs.
y_m(i)=(4.*y_m(i-1)-y_m(i-2))/3+(2/3).*h*(3*f_m(t(i)))
% ^^^^
Here you provide 1 input only.
Lateef Adewale Kareem
2022 年 5 月 29 日
%% 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')
0 件のコメント
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!