0

I would like to solve that problem:

Let say I define $F[x]$ function:

F[x_] := Integrate[x^2, x]

Then I want to calculate eg. $F[2]$, but Mathematica emits an Integrate::ilim error ("Invalid integration variable or limit(s) in 2.") and throws me something strange: $\int 4 d2$. Why it puts "$d2$" instead of "$dx$"? How to solve it, so I can easily use my $F[x]$ function?

We all know that $\int x^2 dx = \frac{x^3}{3}$, so the function $F(x)$ should be equal $F(x)=\frac{x^3}{3}$ and then $F(2) = \frac{2^3}{3}=\frac{8}{3}$ but it's not :/

Michael E2
  • 235,386
  • 17
  • 334
  • 747

1 Answers1

0

You want to do the integration first, then use the result of the integration to define the function. That is don like this:

Block[{x}, f[x_] = Integrate[x^2, x]];

Then

Definition[f]

f[x_] = x^3/3

and

f[2]

8/3

which is what you expect. The way you defined F, the integration expression is held unevaluated until F is called. When is F is called with 2, then 2 replaces each occurrence the symbol x in the integral expression and then the integral is evaluated. That is,

Integrate[x^2, x]

becomes

Integrate[2^2, 2]

You need the learn that difference between SetDelayed ( := ) and Set ( = ). The difference is both important and useful when defining functions in Mathematica.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257