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