The forward Euler scheme for an ordinary differential equation
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Brendan Clark
le 11 Avr 2021
Réponse apportée : Alan Stevens
le 11 Avr 2021
I'm having a lot of trouble with a homework problem that requires me to plot a forward euler scheme. I feel like I'm either close to getting somewhere, or, I've gone about solving this problem entirely wrong.
The problem is:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/579807/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/579812/image.jpeg)
The code I have thus far is:
clear variables
clc
n=100;
h=0.1;
k=0;
x(k+1)=0;
y(k+1)=0;
for k=1
x(k+1)=x*k+h;
y(k+1)=y*k+h*(9.8-0.196*y1);
end
for k=2
x(k+1)=x*k+h;
y(k+1)=y*k+h*(9.8-0.196*y2);
end
for k=3
x(k+1)=x*k+h;
y(k+1)=y*k+h*(9.8-0.196*y3);
end
for k=4
x(k+1)=x*k+h;
y(k+1)=y*k+h*(9.8-0.196*y4);
end
plot(x,y)
I appreciate any pointers that anyone may have to help get me moving in the right direction.
0 commentaires
Réponse acceptée
Alan Stevens
le 11 Avr 2021
More like this
n=100;
h=0.1;
k=0;
x(1)=0;
y(1)=48;
for k=1:n
x(k+1)=x(k)+h;
y(k+1)=y(k)+h*(9.8-0.196*y(k));
end
plot(x,y)
0 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!