Lotka-Volterra Approximate Solution Error: Trapezoid Method in Matlab

Click For Summary
SUMMARY

The forum discussion focuses on calculating the error of the Trapezoid Method for approximating population dynamics of wolves and moose using MATLAB. The user implements a series of trapezoid approximations with decreasing 'h' values, expecting a log-log graph of 'h-values' versus error to yield a slope of 2 due to the method's order of accuracy. However, the observed slope is 1, indicating a misunderstanding of error estimates. The discussion highlights the distinction between local and global error estimates in numerical integration.

PREREQUISITES
  • Understanding of the Lotka-Volterra equations for population dynamics
  • Familiarity with numerical integration methods, specifically the Trapezoid Method
  • Proficiency in MATLAB programming for implementing algorithms
  • Knowledge of error analysis in numerical methods
NEXT STEPS
  • Explore local versus global error estimates in numerical integration
  • Learn about the implementation of adaptive step size methods in MATLAB
  • Investigate the use of MATLAB's built-in functions for error analysis
  • Study the impact of varying 'h' values on convergence in numerical methods
USEFUL FOR

Mathematics students, researchers in computational biology, and MATLAB programmers interested in numerical methods for solving differential equations.

gpax42
Messages
25
Reaction score
0
I'm trying to calculate the error of the Trapezoid Method in my population approximations for wolves and moose over time given certain parameters. Ultimately what i need to do is perform a series of trapezoid approximations using different 'h' values. Each successive 'h' value I use is half the previous value which can be seen in my code below. As my 'h' value gets smaller, the error between successive final population counts of moose and wolves should also be decreasing. Due to the trapezoid method's order of accuracy, i should expect the log-log graph of the 'h-values' vs. 'error' to have a slope of 2. However, mine still has a slope of 1. I know deciphering my code is a pain, but I'd be extremely grateful to anyone that can point me in the right direction... Thanks a million!

%% Trapezoid Error

T = 50;

N = 50;
h = T/N;
w = [20]; %taken from wolf population data
m = [563]; %taken from moose population data

%parameters calculated by least squares for the lotka-volterra equation

c = [-0.0496 -0.0001 -0.1796 -0.0071];
c1 = c(1);
c2 = c(2);
c3 = c(3);
c4 = c(4);

%anonymous function assignments for the two differential equations defined by lotka-volterra

f1 = @(w,m) (c1*w - c2*w*m);
f2 = @(w,m) (-c3*m + c4*w*m);

for i = 1:13
for n = 1:N
w_pred = w(end) + h*f1(w(end),m(end));
m_pred = m(end) + h*f2(w(end),m(end));
w(end+1) = w(end) + h/2*(f1(w(end),m(end)) + f1(w_pred,m_pred));
m(end+1) = m(end) + h/2*(f2(w(end),m(end)) + f2(w_pred,m_pred));
end
wfinal(i) = w(length(w));
mfinal(i) = m(length(m));
hval(i) = h;
h = h/2;

%once the 13th iteration is complete, plot the data, otherwise, perform iterations again with halved 'h' value

if i == 13
TrapError = abs(wfinal(2:end) - wfinal(1:end-1)) + abs(mfinal(2:end) - mfinal(1:end-1));
loglog(hval(2:end),TrapError,'s-');
xlabel('h-value')
ylabel('Trapezoid Error')
title('Error from Trapezoid Approx')
grid on
return
end

w = [20];
m = [563];
end
 
Physics news on Phys.org
gpax42 said:
Each successive 'h' value I use is half the previous value which can be seen in my code below. As my 'h' value gets smaller, the error between successive final population counts of moose and wolves should also be decreasing. Due to the trapezoid method's order of accuracy, i should expect the log-log graph of the 'h-values' vs. 'error' to have a slope of 2. However, mine still has a slope of 1.

Are you confusing local and global error estimates?

The local error estimate for one step is Ah^2 (where A is a constant).

But the number of steps for the integration is B/h (were B is another constant)

So the global error estimate (Ah^2)(B/h) = ABh.

I haven't read your code in detail, so apologies if this is irrelevant!
 
Thank you for the helpful response
:smile:
since I'm plotting the loglog of the difference between my final population values(global error) that resulted from halving my h-value, i believe youre correct in noting that my graph should have a slope of 1.

This, however, begs the question of how to get localized error. My approach once again produced a slope of 1... any further suggestions
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
7K
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K