I need a detailed explination of this code

1 次查看(过去 30 天)
So I have this script but i have no clue what it does, and I got the text that says that it is Euler's method to find an approximate solution to the startvalue problem
y' = sin(sqrt(x+y)) with the start value y(0) = 0.4
on the intervall [0,20]. And the following code implements Euler's methode and plots the graph for the approximat solution of y.
But I was wondering what this script does.
So can someone please explain to me line by line what it does?
ymark = @(x,y) sin(sqrt(x+y));
t = 0:0.01:20;
y = zeros(1,length(t));
y(1) = 0.04;
dt = diff(t);
for s= 1:length(t)-1
y(s+1) = y(s)+dt(s)*ymark(t(s),y(s));
end
plot(t,y)
  1 个评论
John D'Errico
John D'Errico 2020-3-24
编辑:John D'Errico 2020-3-24
Do you have any clue what a differential equation is, what it means, etc.? Because Euler's method is the most basic numerical method you will ever see for solving an ordinary differetial equation.
This is what students are taught when they are introduced to the idea of solving an ODE numerically. In fact, the comments that you show, indicate exactly the differential equation that is approximately solved, including the initial value at t==0.
So are you asking someone to tutor you about differential equations from scratch? Taught well, this usually involves a semester or two.

请先登录,再进行评论。

回答(1 个)

Ameer Hamza
Ameer Hamza 2020-3-24

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by