implicit method by three pont backward method

1 回表示 (過去 30 日間)
Faraz Vossoughian
Faraz Vossoughian 2020 年 4 月 14 日
編集済み: darova 2020 年 4 月 26 日
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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by