![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/284456/image.png)
implicit method by three pont backward method
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/284456/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/284456/image.png)
% 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 commentaires
darova
le 14 Avr 2020
I don't understand it
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/284456/image.png)
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);
Réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!