0
|
415 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
GROUPS:

# Using implicit Euler and fixed step size for solving

Posted 1 month ago
 I used implicit Euler and fixed step size to solve the differential equation, but the system prompted that "FixedStep" cannot be used. What is the reason for this and how should I modify the program? system = {vi q[t] == l il'[t] + ir[t] r, il[t] == ir[t], il[0] == 0}; control = {q[0] == 1, WhenEvent[Mod[t, \[Tau]] == (2/3) \[Tau], q[t] -> 0], WhenEvent[Mod[t, \[Tau]] == 0, q[t] -> 1]}; pars = {vi -> 24, r -> 22, l -> 2 10^-2, c -> 1 10^-4, \[Tau] -> 25/10 10^-4}; sol = NDSolve[{system, control} /. pars, {il, q}, {t, 0, .2}, StartingStepSize -> step, Method -> {"FixedStep", Method -> "LinearlyImplicitEuler"}, DiscreteVariables -> q]; a = Evaluate[il[t] /. sol]; Plot[a, {t, 0, 0.06}, AxesLabel -> {"s", "il[t]/A"}, PlotLegends -> {"LinearlyImplicitEuler"}, PlotStyle -> {Red}, PlotRange -> All] 
2 Replies
Sort By:
Posted 18 days ago
 The reason you are encountering the error "FixedStep cannot be used" is because the "FixedStep" method is not compatible with the WhenEvent feature in NDSolve. The WhenEvent feature requires an adaptive step size method to handle the event detection accurately.To modify your program, you can switch to an adaptive step size method such as the default method "Automatic" or "BDF" (Backward Differentiation Formula). Here's an updated version of your code using "BDF" as the method: system = {vi q[t] == l il'[t] + ir[t] r, il[t] == ir[t], il[0] == 0}; control = {q[0] == 1, WhenEvent[Mod[t, τ] == (2/3) τ, q[t] -> 0], WhenEvent[Mod[t, τ] == 0, q[t] -> 1]}; pars = {vi -> 24, r -> 22, l -> 2 10^-2, c -> 1 10^-4, τ -> 25/10 10^-4}; sol = NDSolve[{system, control} /. pars, {il, q}, {t, 0, 0.2}, Method -> {"EquationSimplification" -> "Residual", "BDF"}, DiscreteVariables -> q]; a = Evaluate[il[t] /. sol]; Plot[a, {t, 0, 0.06}, AxesLabel -> {"s", "il[t]/A"}, PlotLegends -> {"BDF"}, PlotStyle -> {Red}, PlotRange -> All] In this modified code, I have removed the StartingStepSize option since we are now using an adaptive step size method. I have also replaced the Method -> {"FixedStep", Method -> "LinearlyImplicitEuler"} with Method -> {"EquationSimplification" -> "Residual", "BDF"} smash karts to specify the "BDF" method for solving the differential equation.
Posted 26 days ago
 Your code gives two errors. The first is that step is undefined. If I fix that, then I get an error that tells me why I can't use "FixedStep": NDSolve::nodae: The method NDSolveFixedStep is not currently implemented to solve differential-algebraic equations. Use Method -> Automatic instead. It has nothing to do with "LinearlyImplicitEuler". I think the only DAE method is IDA.If you differentiate the algebraic equation and choose an admissible step size, then it works: system = {vi q[t] == l il'[t] + ir[t] r, D[il[t] == ir[t], t], il[0] == 0, ir[0] == 0} control = {q[0] == 1, WhenEvent[Mod[t, \[Tau]] == (2/3) \[Tau], q[t] -> 0], WhenEvent[Mod[t, \[Tau]] == 0, q[t] -> 1]}; pars = {vi -> 24, r -> 22, l -> 2 10^-2, c -> 1 10^-4, \[Tau] -> 25/10 10^-4}; step = \[Tau]/3 /. pars sol = First@ NDSolve[{system, control} /. pars, {il, q}, {t, 0, .2}, StartingStepSize -> step, Method -> {"FixedStep", Method -> "LinearlyImplicitEuler"}, DiscreteVariables -> q] `
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.