0
$\begingroup$

Given an Integral I(t) which is a function of a constant tc, this constant is determined with the condition I(tc)=0, how can I add this condition?

$\endgroup$
1
  • 3
    $\begingroup$ Please show an actual example in code $\endgroup$
    – MarcoB
    Nov 27, 2023 at 14:52

1 Answer 1

2
$\begingroup$

As an example, we take a simple function that we can integrate analytically:

f[t_] = t + 2;

Integrate analytically:

F[tc] = Integrate[f[t], {t, -3, tc}] // Expand
(*    3/2 + 2 tc + tc^2/2    *)

Solve analytically:

Solve[F[tc] == 0, tc]
(*    {{tc -> -3}, {tc -> -1}}    *)

Let's see if we can get the second point, $t_c=-1$, numerically. We set up a differential equation for $F_n(t)$ and print an event whenever the value of the integral crosses zero,

NDSolve[{Fn'[t] == f[t], Fn[-3] == 0, 
  WhenEvent[Fn[t] > 0, Print[InputForm[t]]]}, Fn, {t, -3, 3}];
(*    -1.0000000094830408    *)

Same with Sow/Reap to catch the result for further use:

Tc = Reap[NDSolve[{Fn'[t] == f[t], Fn[-3] == 0,
          WhenEvent[Fn[t] > 0, Sow[t]; "StopIntegration"]},
          Fn, {t, -3, 3}]][[2, 1, 1]]
(*    -1.    *)

Here we're also stopping the integration when the event happens.

$\endgroup$

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