1
$\begingroup$

I have the following set of equations:

$$ T_{man} (\phi_{max}, p_{max}) := \frac{\phi_{max}}{p_{max}} $$ $$ \dot\phi_{ac} (T_{trig}, \phi_{max}, p_{max},t) := \begin{cases} 0 & t<T_{trig} \\ p_{max} & T_{trig} < t < T_{trig} + T_{man} (\phi_{max}, p_{max}) \\ 0 & T_{trig} + T_{man} (\phi_{max}, p_{max}) < t \end{cases} $$ $$ \phi_{ac} (T_{trig}, \phi_{max}, p_{max}, \phi_0,t) := \int_0^t \dot\phi_{ac} (T_{trig}, \phi_{max}, p_{max},\tau)\,d\tau + \phi_0 $$ $$ \dot \chi_{ac} (T_{trig}, \phi_{max}, p_{max}, \phi_0, V_{ac}, t) := \frac{g_0}{V_{ac}} \tan(\phi_{ac} (T_{trig}, \phi_{max}, p_{max}, \phi_0,t)) $$ $$ \chi_{ac} (T_{trig}, \phi_{max}, p_{max}, \phi_0, V_{ac}, \chi_{ac0}, t) := \int_0^t \dot \chi_{ac} (T_{trig}, \phi_{max}, p_{max}, \phi_0, V_{ac}, k) \, dk + \chi_{ac0} $$

In Mathematica:

g0 = 9.81;

Tman[\[Phi]max_, pmax_] := \[Phi]max / pmax;

D\[Phi]ac[Ttrig_, \[Phi]max_, pmax_, t_] := If[Ttrig < t < Ttrig + Tman[\[Phi]max, pmax], pmax, 0];

\[Phi]ac[Ttrig_, \[Phi]max_, pmax_, \[Phi]0_, t_] := Integrate[D\[Phi]ac[Ttrig, \[Phi]max, pmax, \[Tau]],{\[Tau],0,t}] + \[Phi]0;

DXac[Ttrig_, \[Phi]max_, pmax_, \[Phi]0_, Vac_, t_] := 
  g0*Tan[\[Phi]ac[Ttrig, \[Phi]max, pmax, \[Phi]0, t]]/Vac;

Xac[Ttrig_, \[Phi]max_, pmax_, \[Phi]0_, Vac_, Xac0_, t_] := Integrate[DXac[Ttrig, \[Phi]max, pmax, \[Phi]0, Vac, k], {k, 0, t}, Assumptions -> Element[k, Reals]] + Xac0;

When I try to do some plots, the following 2 are succesful:

Manipulate[
 Plot[\[Phi]ac[Ttrig, \[Phi]max, pmax, 0, t], {t, 0, 150}
  , PlotRange -> {{0, 150}, {-30*\[Pi]/180, 70*\[Pi]/180}}] ,
 {Ttrig , 0, 50} ,
 {pmax , \[Pi]/180, 5*\[Pi]/180},
 {\[Phi]max, 20*\[Pi]/180, 60*\[Pi]/180}]


Manipulate[
 Plot[DXac[Ttrig, \[Phi]max, pmax, 0, 45, t], {t, 0, 150}
  , PlotRange -> {{0, 150}, {-0.2, 0.5}}] ,
 {Ttrig , 0, 50} ,
 {pmax , \[Pi]/180, 5*\[Pi]/180},
 {\[Phi]max, 20*\[Pi]/180, 60*\[Pi]/180}]

But the last one is not:

Manipulate[
 Plot[Xac[Ttrig, \[Phi]max, pmax, 0, 45, 0, t], {t, 0, 150}
  , PlotRange -> {{0, 150}, {0, \[Pi]}}] ,
 {Ttrig , 0, 50} ,
 {pmax , \[Pi]/180, 5*\[Pi]/180},
 {\[Phi]max, 20*\[Pi]/180, 60*\[Pi]/180}]$$$

and I keep getting

Integrate::pwrl: Unable to prove that integration limits {0,k} are real. Adding assumptions may help.

despite the explicit assumption that k is real (as you can see above). After a while a plot appears, but is on an error-red background/highlighting, and changing the Manipulate[] variables sometimes leads to nothing being shown.

Is there some mistake in my code? Should I use a different function? Should I change my variable names?

$\endgroup$
1
  • $\begingroup$ If it is relevant, I have Mathematica 11.3 $\endgroup$ – Federico May 11 '20 at 11:49
1
$\begingroup$

I would suggest that you simplify some of your definitions as follows:

g0 = 9.81;
Tman[ϕmax_, pmax_] = ϕmax/pmax; (* No need to have SetDelayed here *)

(*Express your If condition as a Boole expression within Integrate, then        *)
(*pre-calculate the integral explicitly rather than re-calculating it every time*)
ϕac[Ttrig_, ϕmax_, pmax_, ϕ0_, t_] = 
    Integrate[Boole[Ttrig < t < Ttrig + Tman[ϕmax, pmax]], {τ, 0, t}] + ϕ0;

(* Once more, no need for SetDelayed here; just define it once and for all *)
DXac[Ttrig_, ϕmax_, pmax_, ϕ0_, Vac_, t_] = g0*Tan[ϕac[Ttrig, ϕmax, pmax, ϕ0, t]]/Vac;


(* The following value is only used for plotting, i.e. numerically,          *)
(* so use NIntegrate instead of Integrate, but use NumericQ to evaluate only *)
(* after numeric values have been assigned to all variables                  *)
Xac[Ttrig_?NumericQ, ϕmax_?NumericQ, pmax_?NumericQ, 
    ϕ0_?NumericQ, Vac_?NumericQ, Xac0_?NumericQ, t_?NumericQ] := 
  NIntegrate[DXac[Ttrig, ϕmax, pmax, ϕ0, Vac, k], {k, 0, t}] + Xac0;

You can then work with your Manipulate (although I still recommend that you limit the number of PlotPoints used; you could also look into setting a low value for MaxRecursion):

Manipulate[
  Plot[
    Xac[Ttrig, ϕmax, pmax, 0, 45, 0, t], {t, 0, 90}, 
    PlotRange -> All, PlotPoints -> 40
  ],
  {Ttrig, 0, 50}, 
  {pmax, π/180, 5*π/180},
  {ϕmax, 20*π/180, 60*π/180}
]

it's not very pretty, but you now obtain a plot at least.

$\endgroup$
1
  • $\begingroup$ Later on I need Xac for further computation. I used the plot only to check that the integral was working, and I posted only what was needed to get the error. I'll try anyway everything you suggested, hopefully it will help me. Thank you! $\endgroup$ – Federico May 12 '20 at 5:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.