How can I evaluate integration with a number?

I have some functions created as follows:

f(x):=1-2**-x$
g(y):=integrate(f(x), x, 0, y)$

and rated them:

f(1)$float(%);
g(1)$float(%);

but for g (1), instead of a numerical answer, I got a symbolic answer. Using float () was an attempt to get a numerical answer, but it just turned all the members of the integral into floats.

How can I get g (1) as a number?

+3
source share
2 answers

Why not just do it (by the definition of a certain integral):

f(x):=1-2**-x$
gg(x):=''(integrate(f(x), x))$
g(y):=gg(y) - gg(0)$
Operator

'' (quote-quote) is used to force an assessment: = of the right side before assignment.

+3
source

If you are only interested in a numerical solution, you can use numerical integration. For example, you can use quad_qag (f(x), x, a, b, key, [epsrel, epsabs, limit]).

:

f(x) := 1-2^(-x);
g(y):= quad_qag(f(x), x, 0, y, 3, epsrel=10d-8)$
g(1);

:

[0.27865247955552,3.093663986714272*10^-15,31,0]

- ,

- ,

- , ,

- ;

  • 0, ;
  • 1, -;
  • 2, ;
  • 3, ,
  • 6, .

BTW, 1-1/(2 * log (2)), 0,27865.

0

Source: https://habr.com/ru/post/1786246/


All Articles