1
$\begingroup$

I'm trying to solve an ODE where I need to integrate over the entire solution (up to the calculated time step) of one of the state variables.

The equations look as follows

enter image description here

I outline below two pieces of code.

The first code below is without the complexity I'm referring to (bolded in the equation description above), and it runs well.

\[Delta][t_] := 1 - 1/4 (1 - Exp[-(t/10)]);
d\[Delta][t_] := -(1/40) Exp[-(t/10)];
V[t_] := 0.1 + 5/(1 - Exp[-\[Delta][t]]); 

c[\[Phi]_, A_?NumericQ, u_?NumericQ] := 
  Module[{}, 
   N@If[u == 0, 1/A, 
     u/Sqrt[4 A] (Exp[-Sqrt[A] u Cos[\[Phi]]]/
       BesselI[1, u Sqrt[A]]) ]] ; 
uSS[A_?NumericQ, u_?NumericQ] := 
  2 NIntegrate[
    Cos[\[Phi]]/(1 + c[\[Phi], A, u]), {\[Phi], -\[Pi] + 
      10^-7, \[Pi] - 10^-7}, Method -> "LocalAdaptive"];

(*Define the differential equations*)
dAdt[A_?NumericQ, V_, u_?NumericQ, 
   t_] := (2 A)/3 (1 - 1/(4 V)) d\[Delta][t] - 
   A^2/(18 \[Pi]) (A^3/
       V^2 (2 - 
         1/\[Pi] NIntegrate[
           1/(1 + c[\[Phi], A, u]), {\[Phi], -\[Pi] + 10^-7, \[Pi] - 
             10^-7}, Method -> "LocalAdaptive"]) - 8 \[Pi]);

dUdt[A_?NumericQ, u_?NumericQ] := -10 (u - uSS[A, u]); 
{Asol, Usol} = 
  NDSolveValue[{A'[t] == dAdt[A[t], V[t], u[t], t], 
    u'[t] == dUdt[A[t], u[t]], A[0] == 5, u[0] == N@10^-4}, {A, 
    u}, {t, 0, 50}, 
   Method -> {"EquationSimplification" -> "Residual"}];
Plot[{Asol[t], V[t], Usol[t]}, {t, 0, 50}, PlotRange -> All, 
 PlotLegends -> "Expressions"]

The second piece of code below is my attempt to include the non-trivial non-linear addition of the dependence in the state variable A in the equation. This code is not working.

Int[t_, A_] := 
  NIntegrate[A'[s] Exp[-((t - s))], {s, 0, t}, 
   Method -> "LocalAdaptive"];
\[Delta][t_, A_] := 
  1 + 1/40 ((A - 1) + Int[t, A]) - 1/4 (1 - Exp[-(t/10)]);
d\[Delta][t_, A_] := 1/40 (A'[t] - Int[t, A] - Exp[-(t/10)]);
V[t_, A_] := 0.1 + 5/(1 - Exp[-\[Delta][t, A]]); 

c[\[Phi]_, A_?NumericQ, u_?NumericQ] := 
  Module[{}, 
   N@If[u == 0, 1/A, 
     u/Sqrt[4 A] (Exp[-Sqrt[A] u Cos[\[Phi]]]/
       BesselI[1, u Sqrt[A]]) ]] ; 
uSS[A_?NumericQ, u_?NumericQ] := 
  2 NIntegrate[
    Cos[\[Phi]]/(1 + c[\[Phi], A, u]), {\[Phi], -\[Pi] + 
      10^-7, \[Pi] - 10^-7}, Method -> "LocalAdaptive"];

(*Define the differential equations*)
dAdt[A_?NumericQ, V_, u_?NumericQ, 
   t_] := (2 A)/3 (1 - 1/(4 V)) d\[Delta][t, A] - 
   A^2/(18 \[Pi]) (A^3/
       V^2 (2 - 
         1/\[Pi] NIntegrate[
           1/(1 + c[\[Phi], A, u]), {\[Phi], -\[Pi] + 10^-7, \[Pi] - 
             10^-7}, Method -> "LocalAdaptive"]) - 8 \[Pi]);

dUdt[A_?NumericQ, u_?NumericQ] := -10 (u - uSS[A, u]); 
{Asol, Usol} = 
  NDSolveValue[{A'[t] == dAdt[A[t], V[t, A[t]], u[t], t], 
    u'[t] == dUdt[A[t], u[t]], A[0] == 5, u[0] == N@10^-4}, {A, 
    u}, {t, 0, 50}, 
   Method -> {"EquationSimplification" -> "Residual"}];
Plot[{Asol[t], V[t, Asol[t]], Usol[t]}, {t, 0, 50}, PlotRange -> All, 
 PlotLegends -> "Expressions"]

I wish to find a way to integrate in the equation this new dependece in A, and have an explanation of why and how to do this in mathematica.

$\endgroup$
1
  • $\begingroup$ In second code you have to solve equation A'[t]=f[A'[t],A[t],u[t],t]]. Before this step we should solve algebraic equation x=f[x, A[t], u[t], t] and express x=A'[t] as a function of A[t],u[t],t. $\endgroup$ Commented Aug 16 at 16:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.