What's wrong with this code?
显示 更早的评论
clear all
%%Initialization of Parameters
it = 0;
ft = 2;
h = 0.2;
iy = 0;
%%Derived Variables
numSteps = (ft - it)/h;
soln = zeros(1, numSteps+1);
soln(1) = iy;
timeAxis = [it: h: ft]
%%Anonymous Functions
f=@(y) 1+y^2;
%%For Loop
for i = 2:numSteps+1
soln(i) = soln(i-1) + h*(f(soln(i-1)));
end
%%Plot
figure(1)
plot(timeAxis, soln)
grid on
Every time this is run, the solutions run up exponentially and I know it's not correct. I'm not very familiar with the Euler method and I assume it's because I'm not utilizing it correctly. Any suggestions? I'm desperate
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Mathematics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!