我尝试使用 Matlab 编写欧拉方法的“愚蠢”版本,但我总是一无所获。我的代码是垃圾:-(
请参阅此方法的伪代码:
‘set integration range
xi = 0
xf = 0
‘initialize variables
x = xi
y = 1
‘set step size and determine
‘number of calculation steps
dx = 0.5
nc = (xf – xi) / dx
‘ output initial condition
PRINT x, y
‘Loop to implement Euler’s method
‘and display results
DOFOR I = 1, nc
dydx = -(2X**3) + (12X**2) - (20X) + 8.5
y = y + dydx . dx
x = x + dx
PRINT x, y
END DO
我很确定这个伪代码是我需要实现的,但我未能将其转换为 Matlab 代码。请问有什么帮助吗?