I'm trying to implement the Backward Differentiation Formula of order 2 in Matlab and I've been stuck for more than a day. The goal is to solve the Van der Pol equation. I can't find a functioning example for this algorithm on the internet. My attempt so far:
clear; clc; close all;u0=[1;0]; %initial value t0=0; tf=3000; %interval h=0.25; %step size N = floor((tf-t0)/h)+1; %number of points mu = 100; %Van der Pol parameter f = @(t,y) vanderpoldemo(t,y,mu); t = t0:h:tf;
u = zeros(2,N); u(:,1)=u0;
%% BDF2 u(:,2)=u(:,1)+hf(t(1),u(:,1)); %estimate starting value jacobian = @(x) [0,1; -mux(1)x(2)-1,mu(1-x(1)^2)]; G = @(x,i) [x(1);x(2)]-4/3u(:,i-1)+1/3u(:,i-2)-2/3hf(t(i),[x(1);x(2)]); eps = 1e-07; %Newton iteration for i = 3:N e = 1; x = u(:,i-1); while e>eps A = eye(2) - 2h/3jacobian(x); b = G(x,i); temp = A\b; x = x-temp; e = norm(temp); end u(:,i) = x; end
No matter how small I make the step size, the script simply refuses to return any acceptable results. I would greatly appreciate any help.
G, at least running it in octave. Monitoring the computed values ofb, in the second or third loop the values are not small as the theory predicts. Using the formula directly and reducing the step size makes the script run correctly. – Lutz Lehmann Apr 17 '21 at 18:49