implicit method by three pont backward method

2 次查看(过去 30 天)
Hi im trying to code the following implicit method 3 point backward method, but im not gettingt the right answer for y. Can someone help please.The function contains the method, so i believe theres something wrong there.
% problem 2-2 (3PBDF)
x0=0;
xmax=1;
h=0.01*.25;
a=1;
y0=1;
[xs,y]=ThreePointBDF(x0, xmax, h, a, y0);
plot(xs,y)
clear all
close all
f= @(x,y) -y;
x(1)=0;
y(1)=1;
n=10;% number of iterations
h=(1-0)/n; %stepsize h =(b-a)/n)
for i=1:n
y(i+1)=y(i)+h*f(x(i),y(i));
x(i+1)=i*h;
end
x=x(:)
y=y(:)
plot(x,y)
xlabel('x')
ylabel('y')
function [xs,y] = ThreePointBDF(x0, xmax, h, a, y0)
% This function should return the numerical solution of y at x = xmax.
% (It should not return the entire time history of y.)
% TO BE COMPLETED
f=@(x,y) -a*y;
xs=x0:h:xmax;
y=zeros(1,length(xs));
y(1)=y0;
y(2)=y0+h*f(x0,y0);
for i=1:length(xs)-1
disp(i)
y(i+1)=(4/3*y(i+1)-1/3*y(i))+2*h/3*f(xs(i+1),y(i+1));
end
end
  2 个评论
darova
darova 2020-4-14
I don't understand it
I only know something like this
y(i+1) = y(i) + h*f(x(i),y(i));
Maybe in your case this should be
y1 = y(i) + h*f(x(i),y(i));
y(i+1) = 4/3*y(i)-1/3*y(i-1)+2/3*h*f(x(i+1),y1);
Madmiller
Madmiller 2020-4-26
编辑:darova 2020-4-26
I agree. Can you explain more? Im interested too

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by