% % mycub_fe.m % % solve the mycub ode via forward Euler % % usage [t,x] = mycub_fe(dt,T,x0) % % where dt = time step % T = end time % x0 = initial state % % example [t,x] = mycub_fe(.1,1000,[1 1]/100); % function [t,x] = mycub_fe(dt,T,x0) N = ceil(T/dt); x = zeros(N,2); t = zeros(N,1); x(1,:) = x0; t(1) = 0; a = 2; for n=1:N, x(n+1,1) = x(n,1) + dt*(x(n,1)-x(n,1)^3-a*x(n,2)); x(n+1,2) = x(n,2) + dt*(x(n,1)-x(n,2)); t(n+1) = n*dt; end