Trying to code backward euler?

조회 수: 3 (최근 30일)
Brady Retzlaff
Brady Retzlaff 2015년 11월 24일
I am trying to write a code to compute the backward euler approximation of a differential equation. the ODE is dy/dx = -y(x)
so my code looks like
for k = 1:((T/dt)-1)
xb(k+1) = xb(k)+dt;
yb(k+1) = yb(k) + dt*f(yb(k+1),xb(k+1));
end
My problem is that using my equation i am trying to use yb(k+1) to compute itself, which obviously doesnt work, so i get an error 'index exceeds matrix dimension'. How should i resolve this?

답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by