Integral approximation with midpoint method

I want to write a code for the Integral approximation with the midpoint method.
Mathematically, I was thinking like this: y'(t)=f(t,y(t))=-y(t)
The rectangle rule: y(t + h)=y(t) + h · f(t+h/2,y(t)+h/2*f(t,y(t)))
for:
h=0.5 and y(0)=1 (t0=0, y(t0)=1)
I would like to calculate the next step: t1=t0+h=0.5, y(t1)=?
y(t1)=y(t0+h)=y(t0)+h*f(t0+h/2,y(t0)+h/2*f(t0,y(t0)))=
=1+0.5*f(0.25,1+0.25*f(0,1))=
=1+0.5*f(0.25,1+0.25*(-1))=
=1+0.5*f(0.25,0.75) = 1+0.5*(-0.75)=0.625
I don't know how to represent the function f in Matlab (syms ?) so that it would know to calculate f(0,1) for example.
Can someone help me, please?

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

提问:

2017-3-13

Community Treasure Hunt

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

Start Hunting!

Translated by