implicit method by three pont backward method

2 views (last 30 days)
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 Comments
darova
darova on 14 Apr 2020
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 on 26 Apr 2020
Edited: darova on 26 Apr 2020
I agree. Can you explain more? Im interested too

Sign in to comment.

Answers (0)

Categories

Find more on Programming 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!