I need a detailed explination of this code
2 次查看(过去 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
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
2020-3-24
[Give a man a fish, he'll eat for a day; teach a man to fish and he'll eat for a lifetime]
Instead of explaining just this one piece of code, I can point you to documentation, which will help you to understand this code by yourself.
MATLAB commands:
Then about differential equations
Euler Method (ode1) https://www.mathworks.com/matlabcentral/answers/98293-is-there-a-fixed-step-ordinary-differential-equation-ode-solver-in-matlab-8-0-r2012b#answer_107643
New solvers (ode45): https://www.mathworks.com/help/matlab/ref/ode45.html
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!