Maple/Lesson 1: Getting Started

From testwiki
Revision as of 20:24, 23 February 2007 by 128.148.16.184 (talk) (Using functions with Maple)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Chapter 1: Getting Started with Maple

Before You Begin

All the orders given to Maple are in the areas marked with >.
These are the input areas.
Press enter to give the software the order.

>sample code;

The lines of code must end with either a semicolon or a colon. Note the difference between them:

>p - ln( p );
pln(p)
>p - ln (p ):

If the line of code ends with a semicolon, the order is validated and the software displays the answer in the output area. If the line of code ends with a colon, the order is validated, but the answer is not displayed.

Simple computations with Maple

>(1-1/7)*(1+2/3)^2;
5021
> (25)^(1/2);
5
>factorial(15);
1307674368000
>15!;
1307674368000
>sqrt(81);
9
>sqrt(56.81);
7.537240874
>%^2;
56.81

Using variables with Maple

You can affect a value to a variable. Here, 2.14 is affected to the p variable. We can then compute pln(p).

>p:=2.14;
p:=2.14
>p - ln(p);
1.379194171

You can also use more than one variable in a single equation:

>x := 2*a-p;
x:=2a2.14
>x-sqrt(a*p);
2a2.141.462873884a
>expr := a*x^2 + b*x + c = 0;
expr:=ax2+bx+c=0

Using functions with Maple

Maple has a wide range of functions to help you manipulate mathematical expressions:

>f := (a+b)^6;
f:=(a+b)6
>expand(f);
a6+6a5b+15a4b2+20a3b3+15a2b4+6ab5+b6
>factor(%);
(a+b)6
>%%;
a6+6a5b+15a4b2+20a3b3+15a2b4+6ab5+b6
>sin(x)^2+cos(x)^2;
(sin(x))2+(cos(x))2
>simplify(%);
1

Here, the % symbol recalls the last computation made by Maple. %% means you recalls the computation made two steps back. To obtain the the computation made n steps back, repeat the % symbol n times.

You can also substitute variables in an expression with the subs() function:

>subs(a=c, f);
(c+b)6
>subs(a=2, b=4/5, f);
752953615625

The evalf() function evaluates the numeric value of an expression. You may also specify the desired precision.

>evalf(sqrt(3));
1.732050808
>evalf(sqrt(3), 50);
1.7320508075688772935274463415058723669428052538104
>evalf[50](sqrt(3));
1.7320508075688772935274463415058723669428052538104


print(), lprint() and printf() are functions used to display a mathematical expression. print() displays the expression normally, lprint() displays the function in Courier font and to the left of the screen and printf() is the same function used in C or C++ language, where you can display variables using formats: %d represents an integer variable, %f a floating number and \n breaks a line of text:

>f:=a-3/a+1/(a*a+1);
f:=a3a+1a2+1
>print(f);
a3a+1a2+1
>lprint(f);

a-3/a+1/(a^2+1)

>printf("%d %f \n",123,1234/567); 

123 2.176367

Defining a function with Maple

>f := t -> sin(t) - t;
f:=tsin(t)t
>f(3*x + 2);
sin(3x+2)3x2
>g:=(u,v,w)->1/u+exp(u+v)+(u-v+w)^2;
g:=(u,v,w)1u+eu+v+(uv+w)2
>g(2*a,b,3*c);
121a+e2a+b+(2ab+3c)2

Calculus with Maple

Maple can be used to find the integral of a given function. For example, to get the integral of the f(t) function according to t and the g(u,v,w) function according to v, the following commands can be entered:

>Int(f(t), t) = int(f(t), t);
sin(t)tdt=cos(t)12t2
>Int(g(u,v,w), v) = int(g(u,v,w), v);
1u+eu+v+uv+w2dv=vu+eu+v13(uv+w)3
>Int(f(t),t=0..Pi)=int(f(t),t=0..Pi);
0πsin(t)tdt=212π2


Note the difference between Int() and int(). The first one displays the integral while the latter computes it.

Limits, sums and products with Maple

You can also find numeric and symbolic values of sums, limits and products using respectively the functions sum(), limit() and product():

>limit((2*t-3)/(3*t+4),t=infinity);
23
>limit((2*t-3)/(3*t+4),t=-4/3,right); #right-bound of the limit
Sum(i^2,i=1..10)=sum(i^2,i=1..10);
i=110i2=385
Product(1/i,i=1..10)=product(1/i,i=1..10);
i=1101i=13628800

The functions Sum() and Product() only display a Sigma and a Pi symbol; they do not actually compute the sum or the product.

Solving equations with Maple

The solve(eqn,x) function tries to find the value of x in eqn. You can also use more variables or more equations using solve({eqn1,eqn2,...},{x,y,...}):

solve(2*t+3=-t+6*sqrt(2));
1+22
solve(t-15/4*u=5/2*(u-t)+3,u);
1425t1225
solve({a-b=2,a+3*b=7},{a,b});
{a=134,b=54}

Sometimes, the exact solution of an equation might not be found. You can then use the fsolve() to get a numerical approximation:

fsolve(cos(t)=t);
0.7390851332
fsolve({t^3+u=1,u-(t-1)^3=t},{t,u});
{t=0.6941457205,u=0.6655340191}

Plotting functions with Maple

To plot a f(x) function, use plot(f(x),x) function:

plot(sin(t)/t,t=-20..20,title="function t ---> sin t / t");
plot3d(x*exp(-x^2-y^2),x=-2..2,y=-2..2,color=x,orientation=[120,75]);