Skip to content

Investigate errors caused by choosing particular parameters for a RHS #13

@Schlevidon

Description

@Schlevidon

Summary

Investigate a RHS function from the IFDIFF workshop which produces errors during integration. The cause of the errors may be of mathematical nature (i.e. the problem is ill-posed) or it could be related to IFDIFF after all.

Example

The errors only occur for a parameter value of p = 0 or extremely small values of p. Any larger values seem to produce correct behavior.

ODE system

function dx = swbRHS(t,x,p)
    dx = zeros(3,1);
    dx(1) = x(2);
    dx(2) = -x(1);

    if x(1) <= -p
        if x(1) <= p
            if x(2) < 0
                dx(3) = -1;
            else
                dx(3) = 1;
            end
        end
    end
end

Solver code

Note that the plotSensitivities and plotSensitivitiesSwitched functions are only available in the workshop branch.

% task4.m
integrator = @ode45;
options = odeset('AbsTol', 1e-8, 'RelTol', 1e-6);

p = [0];
tEnd = 30;
tSpan = [0 tEnd];
x0 = [0; 1; 0];

% rhs = @(t, x) swbRHS(t, x, p);
% sol = integrator(rhs, tSpan, x0, options);
datahandle = prepareDatahandleForIntegration('swbRHS', 'integrator', integrator, 'options', options);  %% SOLVER or INTEGRATOR
sol = solveODE(datahandle, tSpan, x0, p);

T = 0:0.1:tEnd;
X = deval(sol, T);
plot(T, X(1,:), 'r', T, X(2,:), 'b', T, X(3,:), 'g');

% plotSensitivities(sol, @swbRHS, p, integrator, options);
plotSensitivitiesSwitched(datahandle, sol, p);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions