| > | restart; |
Functions
We can use expressions in order to work with the kinds of functions we see in calculus.
| > | y:= m*x + b; |
| > | eval(y,x=2); |
But sometimes the whole expression/eval combination is just too clunky. An alternative is to create a function.
| > | f:= x -> sin(x^2); |
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); |
| > | f(t); |
| > | f(sqrt(t)); |
If you have an expression and want to make it a function, use:
| > | g:= unapply( p, x ); |
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 ); |
| > | limit( 1/x, x=infinity ); |
| > | limit( x*sin(1/x), x=0 ); |
| > | limit( (sin(t+h)-sin(t))/h, h=0 ); |
| > |
Differentiation
Taking one or more derivatives of a function is easy.
| > | diff( sin(t), t ); |
| > | diff( sin(t), t,t ); |
If you have a function, you can convert it to an expression first.
| > | f(t); |
| > | diff( f(t), 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); |
Here are two ways to find a derivative at a point.
| > | eval( diff(f(x),x), x=1 ); |
| > | D(f)(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 ); |
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 ); |
| > | int( sin(theta), theta=0..Pi/2 ); |
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! |
| > | value(%); |
| > | Int( sin(theta), theta=0..Pi/2 ); |
| > | value(%); |
Sometimes Maple is actually wrong.
| > | int( sin(n*theta), theta ); |
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 ); |
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 ); |