Backward Euler for Van der Pol equation

I'm trying to program the Backward Euler to solve Van der Pol's equation. Theoretically, this method should be stable for any step size h>0. It doesn't produce particularly stellar results, however, and my guess would be that this has to do with the inability of fsolve or the standard fixed point iteration to obtain results. Here's the code for my two attempts:
clear; clc; close all;
u0=[1;0]; %initial value
t0=0; tf=1000; %interval
N = 200; %number of points
h=(tf-t0)/(N-1); %step size
mu = 0.1; %Van der Pol parameter
f = @(t,y) vanderpoldemo(t,y,mu);
t = t0:h:tf;
u = zeros(2,N);
u(:,1)=u0;
%% attempt 1
for i = 2:N
u(:,i)=rand(1,2);
for times = 1:2
u(:,i) = u(:,i-1)+h*f(t(i-1),u(:,i));
end
end
plot(t,u(1,:))
%% attempt 2
for i = 2:N
u(:,i) = fsolve(@(U) u(:,i-1)+h*f(t(i-1),U)-U,rand(1,2), options);
end
I'm quite frustrated by this and would greatly appreciate any help.

Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Release

R2020b

Asked:

on 15 Apr 2021

Community Treasure Hunt

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

Start Hunting!