1
$\begingroup$

I want to evaluate the laplace transform using "Integrate" rather than "LaplaceTransform". However, for some reason the two don't give the same output.

I want to do

F[s_] := Integrate[E^(-s*t)*f[t], {t, 0, Infinity}]

Instead of

F[s_] := LaplaceTransform[f[t], t, s]

However, it gives me the following error:

Integrate::ilim: Invalid integration variable or limit(s) in {0.000102143,0,[Infinity]}. >>

What am I doing wrong?

ps. here is my complete code:

ClearAll[t, s, f, F, T]
k0 = 0.01;
g = 1;
k[t_] := 1/(1 + (1/k0 - 1)*E^(-g*t))
f[t_] := (1/3) (k[t])^(-2/3)


F[s_] := Integrate[E^(-s*t)*f[t], {t, 0, Infinity}]
Plot[{f[t], F[t]}, {t, 0.01, 5}]

The above code works now, but when I add an "NSolve" line, I get a similar problem:

F[s_, T_] := Block[{t}, NIntegrate[E^(-s*t)*f[t], {t, T, Infinity}]]
iir[t_] := NSolve[F[s, t] == 1, s]


Plot[{iir[x]}, {x, 0.01, 5}]

This gives the following error:

NIntegrate::inumr: "The integrand E^(-s\t)/(3\(1/(1+99. E^-t))^(2/3)) has evaluated to non-numerical values for all sampling points in the region with boundaries {{\[Infinity],0.0101019}}. \!\(\*ButtonBox[\">>\",
Appearance->{Automatic, None},
BaseStyle->\"Link\",
ButtonData:>\"paclet:ref/message/NIntegrate/inumr\",
ButtonNote->\"NIntegrate::inumr\"]\)"
$\endgroup$
  • $\begingroup$ I think t has a value. Use Clear[t] or restart your kernel (Quit[]). $\endgroup$ – Szabolcs May 15 '17 at 10:15
  • $\begingroup$ I already did ClearAll[t]. Changing to Clear[t] doesn't help... $\endgroup$ – user56834 May 15 '17 at 10:16
  • 1
    $\begingroup$ You need to show a complete (but minimal) example, otherwise the question will get closed as not being answerable due to insufficient information. We need code that we can copy without modifications, evaluate in a newly started Mathematica session, and immediately see the problem. $\endgroup$ – Szabolcs May 15 '17 at 10:20
  • $\begingroup$ I've added the complete code $\endgroup$ – user56834 May 15 '17 at 10:22
  • $\begingroup$ t is given a value by Plot. Use a different variable, or localize t within F through Block. That said, Integrate should not be used with inexact values (i.e. anything that has a decimal point in it). Compute the integral first, ensuring exact values only. Add Assumptions when necessary, e.g. s>0. Then take that result, assign it to a function, and plot it. Here you are re-computing the integral for every single argument value, and also risking problems due to inexact values. $\endgroup$ – Szabolcs May 15 '17 at 10:28
3
$\begingroup$

The problem happens because Plot temporarily assigns a value to t. t is used within F without any localization (such as Block). This breaks things.

I suggest you avoid using inexact numbers with Integrate. It is known to cause problems sometimes. I also suggest not to re-compute the integral for every argument value of F. Compute it once, then use the result. This also eliminates t from the definition of F, and avoids this problem you see.

ClearAll[t, s, f, F, T, g, k0]
g = 1;
k[t_] := 1/(1 + (1/k0 - 1)*E^(-g*t))
f[t_] := (1/3) (k[t])^(-2/3)

F[s_] = 
 Integrate[E^(-s*t)*f[t], {t, 0, Infinity}, 
  Assumptions -> (k0 > 0 && s > 0)]
(* Hypergeometric2F1[-(2/3), s, 1 + s, (-1 + k0)/k0]/(3 s) *)

k0 = 0.01;

Plot[{f[t], F[t]}, {t, 0.01, 5}]

Notice that I used = instead of :=. Please see:

$\endgroup$
  • $\begingroup$ If I use NIntegrate instead, is it still advisable to use = instead of :=? $\endgroup$ – user56834 May 15 '17 at 11:00
  • $\begingroup$ @Programmer2134 You should understand the difference between = and :=. I included a link to an explanation. If you understand the difference, it will be clear that using = will lead to an error due to symbols being used in the integrand. $\endgroup$ – Szabolcs May 15 '17 at 11:04
  • $\begingroup$ Sorry. I understood = and := in the abstract I think, but didn't make the connection. However, I'm still confused. I've read the entire = vs := tutorial, but I get an error that shouldn't happen if I understand it correctly (therefore I must still misunderstand it...). I've added the code in the main question. $\endgroup$ – user56834 May 15 '17 at 11:14

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