implicit method by three pont backward method
조회 수: 1 (최근 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
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);
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!