主要内容

consistentInitialConditions

Compute consistent initial conditions

Since R2024b

    Description

    f = consistentInitialConditions(F) updates the initial conditions for the ode object F so that they are consistent. That is, the initial conditions are updated to satisfy f(t,y,y') = 0 or My' = f(t,y).

    example

    f = consistentInitialConditions(F,Name=Value) specifies options using one or more name-value arguments. For example, specify FixedValueVariables=[1 0] to enable changes to only the second value variable.

    example

    [f,norm] = consistentInitialConditions(___) also returns the norm of the ODE function with the updated initial conditions. You can specify the second output argument with any of the input argument combinations in previous syntaxes.

    Examples

    collapse all

    Weissinger's equation is

    ty2(y)3=y3(y)2+t(t2+1)y-t2y=0.

    Because the equation is in the generic form f(t,y,y)=0, you can use the ode15i solver to solve the implicit differential equation. Because the solver requires consistent initial conditions, use the consistentInitialConditions function to compute them. Create an ode object and fix the initial value y(t0)=32. Let consistentInitialConditions compute a consistent initial value for the derivative y(t0), starting from an initial guess of y(t0)=0.

    F = ode;
    F.InitialTime = 1;
    F.InitialValue = sqrt(3/2);
    F.InitialSlope = 0;
    F.Solver = "ode15i";
    F.ODEFcn = @weissinger;
    F = consistentInitialConditions(F)
    F = 
      ode with properties:
    
       Problem definition
                   ODEFcn: @weissinger
              InitialTime: 1
             InitialValue: 1.2247
             InitialSlope: 0.8165
                 Jacobian: []
             EquationType: fullyimplicit
    
       Solver properties
        AbsoluteTolerance: 1.0000e-06
        RelativeTolerance: 1.0000e-03
           JacobianMethod: numerical
                   Solver: ode15i
    
      Show all properties
    
    
    

    Create an ode object to represent this implicit system of equations.

    0=2y1-y20=y1+y2

    F = ode;
    F.InitialTime = 0;
    F.Solver = "ode15i";
    F.ODEFcn = @(t,y,yp) [2*yp(1)-y(2); y(1)+y(2)];

    If y1=1, then y2=-1 according to the second equation and y1=-1/2 according to the first equation. Because these values of y1, y1, and y2 satisfy the equations, they are consistent.

    Specify the initial values y1=1, y2=0, and y1=0, which do not satisfy the equations and are therefore inconsistent. Then use the consistentInitialConditions function with a fixed value for y1 to update the initial conditions to be consistent.

    F.InitialValue = [1 0];
    F.InitialSlope = [0 0];
    F = consistentInitialConditions(F,FixedValueVariables=[1 0]);
    F.InitialValue
    ans = 2×1
    
         1
        -1
    
    
    F.InitialSlope
    ans = 2×1
    
       -0.5000
             0
    
    

    Input Arguments

    collapse all

    ODE problem to solve, specified as an ode object. The InitialValue property of the ode object must have a specified value. The InitialSlope property of the ode object does not need to have a specified value if the initial slope can be represented by a vector of zeros. The consistentInitialConditions function treats the InitialValue and InitialSlope values as initial guesses that the ode solver uses to determine the initial conditions.

    Name-Value Arguments

    collapse all

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: f = consistentInitialConditions(F,FixedValueVariables=[1 0])

    Initial values to remain fixed, specified as [] or a vector of 1s and 0s. If FixedValueVariables is [], then consistentInitialConditions can change any guess in F.InitialValue. If you specify FixedValueVariables as a vector of 1s and 0s, then for FixedValueVariables(i) = 1, consistentInitialConditions does not change the guess for F.InitialValue(i).

    You cannot fix more than length(F.InitialValue) components. Depending on the specific ODE problem, certain components of F.InitialValue might not be possible to fix. A best practice is not to fix more components than necessary.

    Initial slopes to remain fixed, specified as [] or a vector of 1s and 0s. If FixedSlopeVariables is [], then consistentInitialConditions can change any guess in F.InitialSlope. If you specify FixedSlopeVariables as a vector of 1s and 0s, then for FixedSlopeVariables(i) = 1, consistentInitialConditions does not change the guess for F.InitialSlope(i).

    You cannot fix more than length(F.InitialSlope) components. Depending on the specific ODE problem, certain components of F.InitialSlope might not be possible to fix. A best practice is not to fix more components than necessary.

    Output Arguments

    collapse all

    ODE problem with updated initial conditions, returned as an ode object.

    Norm of the residual, returned as a numeric vector. The consistentInitialConditions function calculates the norm using the updated initial conditions.

    • A small value of norm indicates that consistentInitialConditions successfully computed initial conditions that satisfy f.ODEFcn = 0.

    • If the value of norm is large, try adjusting the error threshold properties RelativeTolerance and AbsoluteTolerance of the ode object F.

    Version History

    Introduced in R2024b

    See Also