Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
* text=auto

*.fig binary
*.mat binary
*.mdl binary diff merge=mlAutoMerge
*.mdlp binary
*.mex* binary
*.mlapp binary
*.mldatx binary
*.mlproj binary
*.mlx binary
*.p binary
*.sfx binary
*.sldd binary
*.slreqx binary merge=mlAutoMerge
*.slmx binary merge=mlAutoMerge
*.sltx binary
*.slxc binary
*.slx binary merge=mlAutoMerge
*.slxp binary

## Other common binary file types
*.docx binary
*.exe binary
*.jpg binary
*.pdf binary
*.png binary
*.xlsx binary
Binary file modified Examples/LiveExamples/CanonicalSensitivities.mlx
Binary file not shown.
Binary file modified Examples/LiveExamples/StateJumpExample.mlx
Binary file not shown.
Binary file modified Examples/LiveExamples/WhiteCabbageLive.mlx
Binary file not shown.
Binary file modified Examples/LiveExamples/canonicalExRHS_test_live.mlx
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%% Solution ifdiff
initPaths();

integrator = @ode45;
odeoptionsrhs_test = odeset( 'AbsTol', 1e-14,'RelTol', 1e-12);
datahandle = prepareDatahandleForIntegration('whiteCabbageRHS', 'integrator', func2str(integrator), 'options', odeoptionsrhs_test);
Expand Down
2 changes: 1 addition & 1 deletion Examples/ParameterEstimation_WhiteCabbage/test_Cabbage.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%% Solution ifdiff
initPaths();

integrator = @ode45;
odeoptionsrhs_test = odeset( 'AbsTol', 1e-14,'RelTol', 1e-12);
datahandle = prepareDatahandleForIntegration('whiteCabbageRHS', 'integrator', func2str(integrator), 'options', odeoptionsrhs_test);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%% Solution with ifdiff
initPaths();

integrator = @ode45;
odeoptionsrhs_test = odeset( 'AbsTol', 1e-14,'RelTol', 1e-12);
datahandle = prepareDatahandleForIntegration('canonicalExampleRHS', 'integrator', func2str(integrator), 'options', odeoptionsrhs_test);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%% Solution ifdiff
%initPaths();

integrator = @ode45;
odeoptionsrhs_test = odeset( 'AbsTol', 1e-14,'RelTol', 1e-12);
datahandle = prepareDatahandleForIntegration('canonicalExampleRHS', 'integrator', func2str(integrator), 'options', odeoptionsrhs_test);
Expand Down
2 changes: 1 addition & 1 deletion Examples/canonicalExample/analyticalSolution.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
ylabel('\sigma_2(t)')
set(gca, 'FontSize', 24);
set(gca, 'Box', 'off');

%% Solution ifdiff
initPaths();
integrator = @ode45;
odeoptionsrhs_test = odeset( 'AbsTol', 1e-14,'RelTol', 1e-12);
datahandle = prepareDatahandleForIntegration('canonicalExampleRHS', 'integrator', func2str(integrator), 'options', odeoptionsrhs_test);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
initstates = [1 0];
%p = 5.437;
p = 0.5;
%initPaths()
%%

options = odeset('AbsTol', 1e-14, 'RelTol', 1e-12);
Expand Down
2 changes: 1 addition & 1 deletion Examples/canonicalExample/sensitivities_CanonicalExample.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%% Solution with ifdiff
initPaths();

integrator = @ode45;
odeoptionsrhs_test = odeset( 'AbsTol', 1e-14,'RelTol', 1e-12);
datahandle = prepareDatahandleForIntegration('canonicalExampleRHS', 'integrator', func2str(integrator), 'options', odeoptionsrhs_test);
Expand Down
8 changes: 5 additions & 3 deletions Examples/predatorprey_filippov/testpprhs.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@


%% EULER Integration
euler_fname = fullfile('.', 'Examples', 'predatorprey_filippov', sprintf('sol_euler_%.0e.mat', eulerStep));
[owndir, ~] = fileparts(mfilename('fullpath'));
euler_fname = fullfile(owndir, sprintf('sol_euler_%.0e.mat', eulerStep));
if doEuler
fprintf('Integrating with integrator %s...\n', func2str(intEuler))
fprintf('Integrating with integrator %s (might take a while) ...\n', func2str(intEuler))
figure(fignum);
th = tic();
sol_euler = intEuler(@(t,x) pprhs(t,x,p), tspan, x0_1, eulerStep);
time_euler = toc(th); fprintf('Euler took %g s\n', time_euler);
fprintf('Saving result to %s for later reuse.\n', euler_fname);
save(euler_fname, "sol_euler");
elseif isfile(euler_fname)
fprintf('Loading sol_euler from file %s\n', euler_fname);
Expand Down Expand Up @@ -150,8 +152,8 @@ function errorPlot(fignum, x1, y1, y2, intname1, intname2)
if (i == nextout)
X(:,k) = Xi; k = k + 1;
nextout = nextout + ceil(1 / sfac);
if ~mod(i/stepcount, 0.1), fprintf('.'); end
end
if ~mod(floor(100*i/stepcount), 10), fprintf('.'); end
end
fprintf('\n')
T = linspace(tspan(1), tspan(end), ceil(stepcount*sfac)+1);
Expand Down
2 changes: 0 additions & 2 deletions Examples/statejump/bounceball.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
% Solve the bouncing ball problem and plot the solutions and sensitivities
initPaths();

solver = @ode15s;
options = odeset('AbsTol', 1e-8, 'RelTol', 1e-6);

Expand Down
2 changes: 0 additions & 2 deletions Examples/statejump/bounceballError.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
% This is because having to set h_+ to a value slightly above zero is a burden imposed by IFDIFF, so it
% should also factor into the error

initPaths();

% INITIAL DATA
g = 9.807;
gamma = 0.9;
Expand Down
2 changes: 0 additions & 2 deletions Examples/statejump/bounceballZeno.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
% Solve the bouncing ball problem with Zeno's phenomenon treatment and plot the solutions and sensitivities
initPaths();

solver = @ode15s;
options = odeset('AbsTol', 1e-8, 'RelTol', 1e-6);

Expand Down
1 change: 0 additions & 1 deletion Examples/statejump/jumpSensitivities.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
% 2. IFDIFF with standard tolerances and FD step, plus relative error
% 3. IFDIFF with strict tolerances and shorter FD step, plus relative error

initPaths();
[t0, tEnd, p, x0] = jumpSensitivityInitdata();

% CONFIGURATION
Expand Down
2 changes: 0 additions & 2 deletions Examples/statejump/sinCosMain.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
initPaths();

solver = @ode45;
options = odeset('AbsTol', 1e-8, 'RelTol', 1e-6);

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ The file [Readme_Example.m](./Readme_Example.m) contains a self-explaining Matla


# First Run Prerequisites

Before using IFDIFF, it is mandatory to run the `make_mtreeplus` script once.
After starting Matlab, change to the IFDIFF directory and type `make_mtreeplus`.
This scripts generates a modified copy of Matlab's own parser class `mtree`, on which IFDIFF heavily relies.

It is also advisable to initialize the paths needed for IFDIFF by invoking
`initPaths();` once on every new matlab session.
It is advisable to initialize the paths needed for IFDIFF by invoking
`initIFDIFF();` once on every new matlab session.

</br>

Expand All @@ -43,7 +44,7 @@ Preprocessing generates the `datahandle`, the central structure for switching de
We set ODE solver and its options as usual. If not set, default values are used.

```matlab
initPaths(); % Initialise the paths for ifdiff
initIFDIFF(); % Initialise the paths for ifdiff -- needed only once per Matlab session
integrator = @ode45;
odeoptions = odeset('AbsTol', 1e-14, 'RelTol', 1e-12);
datahandle = prepareDatahandleForIntegration('canonicalExampleRHS', 'integrator', func2str(integrator), 'options', odeoptions);
Expand Down
2 changes: 1 addition & 1 deletion Readme_Example.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
% The ODE solver and the ODE options can be set by the user with name-value pairs.
% If unspecified, defaults are used.

initPaths(); % Initialise the paths for ifdiff
initIFDIFF(); % Initialise the paths for ifdiff
integrator = @ode45; % Choose integrator and options
odeoptions = odeset('AbsTol', 1e-8, 'RelTol', 1e-6);

Expand Down
16 changes: 7 additions & 9 deletions clearPaths.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ function clearPaths()
% OUTPUT
% [none]
%
% See also INITPATHS whose changes are undone by CLEARPATHS.
% See also initIFDIFF whose paths additions are undone by CLEARPATHS.


% Get absolute path to directory in which this file resides.
[filePath, ~, ~] = fileparts(mfilename('fullpath'));
% receive the required paths
ifdiffpaths = generateIFDIFFpaths();

% remove them from the search path
rmpath(ifdiffpaths);


rmpath(filePath);
rmpath(genpath(fullfile(filePath, 'Tools')));
rmpath(genpath(fullfile(filePath, 'Examples')));
rmpath(genpath(fullfile(filePath, 'PreprocessedFunctions')));
rmpath(fullfile(filePath, 'ComputeSensitivities'));
rmpath(genpath(fullfile(filePath, 'GenerateFixedBranchingFunctions')));
end
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Without any warning or error, the __naive approach with tight tolerances leads t
With the switching point detection in IFDIFF, after a single call to a preparation routine,
integration is just as simple as before:
```matlab
initPaths(); % initialise the paths for ifdiff (only once)
initIFDIFF(); % initialise IFDIFF (only once)
tspan = [0 20]; x0 = [1;0]; p = 5.437; % set time horizon, initial value, parameter
integrator = @ode45; % choose integrator
odeoptions = odeset('AbsTol', 1e-5, 'RelTol', 1e-3); % set integrator options, here: low accuracy
Expand Down
35 changes: 35 additions & 0 deletions generateIFDIFFpaths.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
function [pathStr, pathList] = generateIFDIFFpaths()
% [pathStr, pathList] = generateIFDIFFpaths()
%
% Generates a character array with all paths for IFDIFF.
% The character array can be passed to addpath or rmpath
%
% INPUT: none
%
% OUTPUT: pathStr --> character array with paths needed/used by IFDIFF
% pathList --> cell array of sub-paths
%
%
% Andreas Sommer, Jul2025
% code@andreas-sommer.eu
%


% get directory this file resides in
[selfdir, ~] = fileparts(mfilename('fullpath'));

% list all IFDIFF pars
pathList = { selfdir ... % main directory of IFDIFF
, genpath(fullfile(selfdir, 'Tools')) ...
, genpath(fullfile(selfdir, 'Examples')) ...
, genpath(fullfile(selfdir, 'PreprocessedFunctions')) ...
, fullfile(selfdir, 'ComputeSensitivities') ... % no subdirs
, genpath(fullfile(selfdir, 'GenerateFixedBranchingFunctions')) ...
};

% combine them into a single path specification
pathStr = strjoin(pathList, pathsep());

% finito
end

23 changes: 23 additions & 0 deletions initIFDIFF.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function initIFDIFF()
% initIFDIFF()
%
% Initializes IFDIFF, setting up paths.
%
% INPUT: none
%
% OUTPUT: none
%
%
% Andreas Sommer, Jul2025
% code@andreas-sommer.eu
%


% receive the required paths
ifdiffpaths = generateIFDIFFpaths();

% add them to the search path at the beginning (search them first)
addpath(ifdiffpaths, '-begin');


end % of function
23 changes: 0 additions & 23 deletions initPaths.m

This file was deleted.

2 changes: 1 addition & 1 deletion speedtracker/commands/RunBenchmarksCommand.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
end

% Main: run the benchmarks and return the results
initPaths();
initIFDIFF();
try
speedtrackerRunner = speedtrackerRunner.run(snapshots, benchmarks);
catch error
Expand Down
4 changes: 2 additions & 2 deletions test/TestHelperFunctions.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ function setPath(testCase)
originalPath = path;
testCase.addTeardown(@path, originalPath);

if ~exist('initPaths', 'file')
if ~exist('initIFDIFF', 'file')
% We are probably in the test directory, so check parent directory
cd('..');
end
initPaths();
initIFDIFF();

% Get absolute path to directory in which this file resides.
[filePath, ~, ~] = fileparts(mfilename('fullpath'));
Expand Down
4 changes: 2 additions & 2 deletions test/TestIgnore.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ function setPath(testCase)
originalPath = path;
testCase.addTeardown(@path, originalPath);

if ~exist('initPaths', 'file')
if ~exist('initIFDIFF', 'file')
% We are probably in the test directory, so check parent directory
cd('..');
end
initPaths();
initIFDIFF();

% Get absolute path to directory in which this file resides.
[filePath, ~, ~] = fileparts(mfilename('fullpath'));
Expand Down
4 changes: 2 additions & 2 deletions test/TestPreprocessing.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ function setPath(testCase)
originalPath = path;
testCase.addTeardown(@path, originalPath);

if ~exist('initPaths', 'file')
if ~exist('initIFDIFF', 'file')
% We are probably in the test directory, so check parent directory
cd('..');
end
initPaths();
initIFDIFF();

% Get absolute path to directory in which this file resides.
[filePath, ~, ~] = fileparts(mfilename('fullpath'));
Expand Down
2 changes: 1 addition & 1 deletion test/TestSensitivities.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
methods(TestClassSetup)
function setup(~)
cd("..");
initPaths();
initIFDIFF();
end
end

Expand Down
10 changes: 5 additions & 5 deletions test/TestSolverCompatibility.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

subway_tspan = [0 65];
subway_x0 = [0; 0; 0];
% subway_p initialized later because we need to initPaths() before
% subway_p initialized later because we need to initIFDIFF() before
subway_rhsFunction = 'newYorkCitySubwayModelRhs';
subway_odeoptions = odeset( 'AbsTol', 1e-20, 'RelTol', 1e-10);
subway_xEnd = [2112.07361577; 0.00124794; 4124.77885608];
Expand All @@ -41,15 +41,15 @@ function setPath(testCase)
originalPath = path;
testCase.addTeardown(@path, originalPath);

if ~exist('initPaths', 'file')
if ~exist('initIFDIFF', 'file')
% We are probably in the test directory, so check parent directory
cd('..');
end
initPaths();
initIFDIFF();

% Get absolute path to directory in which initPaths resides.
% Get absolute path to directory in which initIFDIFF resides.
% This should be the IFDIFF project root directory.
[filePath, ~, ~] = fileparts(which('initPaths'));
[filePath, ~, ~] = fileparts(which('initIFDIFF'));
addpath(fullfile(filePath, 'Examples', 'subway'));
end
function setParameters(testCase)
Expand Down
Loading