> restart;
 

Functions 

 

We can use expressions in order to work with the kinds of functions we see in calculus. 

> y:= m*x + b;
 

m*x+b 

> eval(y,x=2);
 

2*m+b 

But sometimes the whole expression/eval combination is just too clunky. An alternative is to create a function. 

> f:= x -> sin(x^2);
 

proc (x) options operator, arrow; sin(x^2) end proc 

The above says that f is a rule to map a value to the sine of the square of that value. The rule can be applied to numbers, variables, or expressions, with no need to use eval. 

> f(1);
 

sin(1) 

> f(t);
 

sin(t^2) 

> f(sqrt(t));
 

sin(t) 

If you have an expression and want to make it a function, use: 

> g:= unapply( p, x );
 

proc (x) options operator, arrow; x^3-2*x+1 end proc 

Conversely, g(x) is equivalent to the expression p defined earlier. You can easily go back and forth and use whichever is most convenient. 

Limits 

You can take limits of expressions. 

> limit( x^2-1, x=2 );
 

3 

> limit( 1/x, x=infinity );
 

0 

> limit( x*sin(1/x), x=0 );
 

0 

> limit( (sin(t+h)-sin(t))/h, h=0 );
 

cos(t) 

>
 

 

Differentiation 

Taking one or more derivatives of a function is easy.  

> diff( sin(t), t );
 

cos(t) 

> diff( sin(t), t,t );
 

-sin(t) 

If you have a function, you can convert it to an expression first. 

> f(t);
 

sin(t^2) 

> diff( f(t), t );
 

2*cos(t^2)*t 

Alternatively, you can use D. The result is another function representing the derivative. This makes it easy to find values at different arguments.  

> fprime:= D(f);
 

proc (x) options operator, arrow; 2*cos(x^2)*x end proc 

Here are two ways to find a derivative at a point. 

> eval( diff(f(x),x), x=1 );
 

2*cos(1) 

> D(f)(1);
 

2*cos(1) 

The derivative of an undefined symbol is a purely symbolic result. Observe the difference in these next two statements: 

> diff( g(t), t );
 

diff(g(t), t) 

> diff( g, t );
 

0 

You must make the dependence on the independent variable explicitly clear.   

Integration 

 

You can do indefinite or definite integration. In the indefinite case, Maple does not add the integration constant! 

> int( sin(theta), theta );
 

-cos(theta) 

> int( sin(theta), theta=0..Pi/2 );
 

1 

If you capitalize Int, Maple just spits back the integral without trying to evaluate it. Then, you can use value to ask it to find the integral. This is a useful habit, to make sure you are getting the integral you think you asked for.  

> Int( sin(theta), t=0..Pi/2 );   # oops!
 

Int(sin(theta), t = 0 .. 1/2*Pi) 

> value(%);  
 

1/2*sin(theta)*Pi 

> Int( sin(theta), theta=0..Pi/2 );
 

Int(sin(theta), theta = 0 .. 1/2*Pi) 

> value(%);
 

1 

Sometimes Maple is actually wrong. 

> int( sin(n*theta), theta );
 

-cos(n*theta)/n 

What are we to make of that last result if n=0? You could answer that the original problem is very easy in that case. But here is another one where it is not. 

> int( x^(n-1), x );
 

x^n/n 

As you know, most integrals are hard. Many are impossible. If Maple can't get the answer, it just returns the unevaluated form. 

> int( sin(cos(theta)), theta );
 

int(sin(cos(theta)), theta)