lec19.mws

L-19 MCS 320 Monday 10 October 2005

> restart;

1. Taking Antiderivatives

We have an inert version "Int" and the version "int" which actually calculates.

> exint := Int((x^2-1)/(x^5+1),x);

exint := Int((x^2-1)/(x^5+1), x)

> value(exint);

1/10*5^(1/2)*ln(-2*x^2+x+5^(1/2)*x-2)+arctan((-4*x+1+5^(1/2))/(10-2*5^(1/2))^(1/2))/(10-2*5^(1/2))^(1/2)-3/5*arctan((-4*x+1+5^(1/2))/(10-2*5^(1/2))^(1/2))*5^(1/2)/(10-2*5^(1/2))^(1/2)-1/10*5^(1/2)*ln(...1/10*5^(1/2)*ln(-2*x^2+x+5^(1/2)*x-2)+arctan((-4*x+1+5^(1/2))/(10-2*5^(1/2))^(1/2))/(10-2*5^(1/2))^(1/2)-3/5*arctan((-4*x+1+5^(1/2))/(10-2*5^(1/2))^(1/2))*5^(1/2)/(10-2*5^(1/2))^(1/2)-1/10*5^(1/2)*ln(...

> anti_derivative := int((x^2-1)/(x^5+1),x);

anti_derivative := 1/10*5^(1/2)*ln(-2*x^2+x+5^(1/2)*x-2)+arctan((-4*x+1+5^(1/2))/(10-2*5^(1/2))^(1/2))/(10-2*5^(1/2))^(1/2)-3/5*arctan((-4*x+1+5^(1/2))/(10-2*5^(1/2))^(1/2))*5^(1/2)/(10-2*5^(1/2))^(1/...anti_derivative := 1/10*5^(1/2)*ln(-2*x^2+x+5^(1/2)*x-2)+arctan((-4*x+1+5^(1/2))/(10-2*5^(1/2))^(1/2))/(10-2*5^(1/2))^(1/2)-3/5*arctan((-4*x+1+5^(1/2))/(10-2*5^(1/2))^(1/2))*5^(1/2)/(10-2*5^(1/2))^(1/...

The second time, the answer came much faster, although there seems to be no remember table:

> interface(verboseproc=3);

> op(4,eval(int));

> print(int);

proc () local answer; option `Copyright (c) 1997 Waterloo Maple Inc. All rights reserved.`; if nargs = 2 and type(args[2], =('name', '{complex(float) .. algebraic, algebraic .. complex(float)}')) then...proc () local answer; option `Copyright (c) 1997 Waterloo Maple Inc. All rights reserved.`; if nargs = 2 and type(args[2], =('name', '{complex(float) .. algebraic, algebraic .. complex(float)}')) then...proc () local answer; option `Copyright (c) 1997 Waterloo Maple Inc. All rights reserved.`; if nargs = 2 and type(args[2], =('name', '{complex(float) .. algebraic, algebraic .. complex(float)}')) then...proc () local answer; option `Copyright (c) 1997 Waterloo Maple Inc. All rights reserved.`; if nargs = 2 and type(args[2], =('name', '{complex(float) .. algebraic, algebraic .. complex(float)}')) then...proc () local answer; option `Copyright (c) 1997 Waterloo Maple Inc. All rights reserved.`; if nargs = 2 and type(args[2], =('name', '{complex(float) .. algebraic, algebraic .. complex(float)}')) then...proc () local answer; option `Copyright (c) 1997 Waterloo Maple Inc. All rights reserved.`; if nargs = 2 and type(args[2], =('name', '{complex(float) .. algebraic, algebraic .. complex(float)}')) then...proc () local answer; option `Copyright (c) 1997 Waterloo Maple Inc. All rights reserved.`; if nargs = 2 and type(args[2], =('name', '{complex(float) .. algebraic, algebraic .. complex(float)}')) then...proc () local answer; option `Copyright (c) 1997 Waterloo Maple Inc. All rights reserved.`; if nargs = 2 and type(args[2], =('name', '{complex(float) .. algebraic, algebraic .. complex(float)}')) then...proc () local answer; option `Copyright (c) 1997 Waterloo Maple Inc. All rights reserved.`; if nargs = 2 and type(args[2], =('name', '{complex(float) .. algebraic, algebraic .. complex(float)}')) then...proc () local answer; option `Copyright (c) 1997 Waterloo Maple Inc. All rights reserved.`; if nargs = 2 and type(args[2], =('name', '{complex(float) .. algebraic, algebraic .. complex(float)}')) then...

> op(4,eval(`int/int`));

TABLE([([(x^2-1)/(x^5+1), x], 10, _EnvCauchyPrincipalValue, _EnvAllSolutions, _EnvContinuous) = 1/10*5^(1/2)*ln(-2*x^2+x+5^(1/2)*x-2)+arctan((-4*x+1+5^(1/2))/(10-2*5^(1/2))^(1/2))/(10-2*5^(1/2))^(1/2)...TABLE([([(x^2-1)/(x^5+1), x], 10, _EnvCauchyPrincipalValue, _EnvAllSolutions, _EnvContinuous) = 1/10*5^(1/2)*ln(-2*x^2+x+5^(1/2)*x-2)+arctan((-4*x+1+5^(1/2))/(10-2*5^(1/2))^(1/2))/(10-2*5^(1/2))^(1/2)...TABLE([([(x^2-1)/(x^5+1), x], 10, _EnvCauchyPrincipalValue, _EnvAllSolutions, _EnvContinuous) = 1/10*5^(1/2)*ln(-2*x^2+x+5^(1/2)*x-2)+arctan((-4*x+1+5^(1/2))/(10-2*5^(1/2))^(1/2))/(10-2*5^(1/2))^(1/2)...TABLE([([(x^2-1)/(x^5+1), x], 10, _EnvCauchyPrincipalValue, _EnvAllSolutions, _EnvContinuous) = 1/10*5^(1/2)*ln(-2*x^2+x+5^(1/2)*x-2)+arctan((-4*x+1+5^(1/2))/(10-2*5^(1/2))^(1/2))/(10-2*5^(1/2))^(1/2)...TABLE([([(x^2-1)/(x^5+1), x], 10, _EnvCauchyPrincipalValue, _EnvAllSolutions, _EnvContinuous) = 1/10*5^(1/2)*ln(-2*x^2+x+5^(1/2)*x-2)+arctan((-4*x+1+5^(1/2))/(10-2*5^(1/2))^(1/2))/(10-2*5^(1/2))^(1/2)...

So getting to the remember table is a bit more involved...

The second thing we may want to do is to verify the answer.  We can take the derivative of the recently computed antiderivative.

> da := diff(anti_derivative,x);

da := 1/10*5^(1/2)*(-4*x+1+5^(1/2))/(-2*x^2+x+5^(1/2)*x-2)-4/((10-2*5^(1/2))*(1+(-4*x+1+5^(1/2))^2/(10-2*5^(1/2))))+12/5*5^(1/2)/((10-2*5^(1/2))*(1+(-4*x+1+5^(1/2))^2/(10-2*5^(1/2))))-1/10*5^(1/2)*(4*...da := 1/10*5^(1/2)*(-4*x+1+5^(1/2))/(-2*x^2+x+5^(1/2)*x-2)-4/((10-2*5^(1/2))*(1+(-4*x+1+5^(1/2))^2/(10-2*5^(1/2))))+12/5*5^(1/2)/((10-2*5^(1/2))*(1+(-4*x+1+5^(1/2))^2/(10-2*5^(1/2))))-1/10*5^(1/2)*(4*...

Why does this seem so different from out original (x^2-1)/(x^5-1)?????

> testeq(da=(x^2-1)/(x^5+1));

FAIL

The probability one test, built-in in the "testeq" command returns inconclusive.

> f := unapply(da,x):

> g := x -> (x^2-1)/(x^5+1):

> r := evalf(rand()/10^12);

r := .4274196691

> evalf(f(r) - g(r));

0.1e-9

So there is not really a difference.

> pf := plot(f(x),x=0..100): pg := plot(g(x),x=0..100):

> plots[display](pf,pg);

[Plot]

2. Definite Integration

Let us move to definite integration, and verify the fundamental theorem of calculus.  We can compute definite integrals via antiderivatives.

> f := 1/x^2;

f := 1/x^2

Let us compute an antiderivative:

> ad := int(f,x);

ad := -1/x

To compute the integral of f from a to b, we apply the fundamental theorem of calculus:

> symbolic_integral := subs(x=b,ad) - subs(x=a,ad);

symbolic_integral := -1/b+1/a

For example:

> subs(a=-1,b=1,symbolic_integral);

-2

However:

> numerical_integral := int(f,x=-1..1);

numerical_integral := infinity

The numerical_integral is right:

> plot(f,x=-1..1,view=[-1..1,0..100]);

[Plot]

>

3. Numerical Integration

In many cases, there is no symbolic antiderivative.

> integrand := exp(cos(x));

integrand := exp(cos(x))

> int(integrand,x);

int(exp(cos(x)), x)

What we still can compute are definite integrals, but then numerically:

> integral := Int(integrand,x=0..1);

integral := Int(exp(cos(x)), x = (0 .. 1))

> val := evalf(integral);

val := 2.341574842

Here we see the usefulness of the inert Int command, because it does not make sense to first try a symbolic antiderivative.

> macro(numint = evalf@Int);

numint

> numint(integrand,x=0..1);

2.341574842

A direct numerical integration routine was invoked, without first trying to integrate it symbolically.

4. Integral Transforms

To go from the time domain to the frequency domain, we apply integral transforms.

> diffeq := diff(y(t),t$2) + y(t) = sin(2*t);

diffeq := diff(y(t), `$`(t, 2))+y(t) = sin(2*t)

> inits := y(0) = 2,D(y)(0) = 1; # initial conditions

inits := y(0) = 2, D(y)(0) = 1

> inttrans[laplace](diffeq,t,s);

s^2*laplace(y(t), t, s)-D(y)(0)-s*y(0)+laplace(y(t), t, s) = 2/(s^2+4)

> subs(laplace(y(t),t,s)=Y(s),%);

s^2*Y(s)-D(y)(0)-s*y(0)+Y(s) = 2/(s^2+4)

> subs(inits,%);

s^2*Y(s)-1-2*s+Y(s) = 2/(s^2+4)

We can solve this equation algebraically, find Y(s) and then go back to the time domain via invlaplace.

5. Integrals with parameters

Maple 7 would have evaluated the following integral:

> int(f,x=a..b);

int(1/x^2, x = (a .. b))

>

which would be wrong if a*b < 0.

> int(f,x=a..b) assuming a>0,b>0;

-(-b+a)/(a*b)

Equivalently, we can impose a global assumptions on a and b:

> assume(a>0,b>0);

> int(f,x=a..b);

(b-a)/(a*b)

The value of the integral depends on whether a and b have the same sign.

6. Summation

> sum('i','i'=0..n);

1/2*(n+1)^2-1/2*n-1/2

>

>