95503 統資軟體課程講義 銘傳大學應用統計資訊學系 蔡桂宏 製作 1...
Post on 19-Dec-2015
269 views
TRANSCRIPT
銘傳大學應用統計資訊學系 蔡桂宏 製作
1
9550395503 統資軟體課程講義統資軟體課程講義
符號數學運算軟體符號數學運算軟體
銘傳大學應用統計資訊學系 蔡桂宏 製作
2
9550395503 統資軟體課程講義統資軟體課程講義
MAPLEMAPLE 軟體簡介軟體簡介
銘傳大學應用統計資訊學系 蔡桂宏 製作
3
Introduction to Maple
Installing Maple Starting Maple The Maple Worksheet Window Accessing Help Pages Entering Expressions in Maple
銘傳大學應用統計資訊學系 蔡桂宏 製作
4
Maple worksheet window
銘傳大學應用統計資訊學系 蔡桂宏 製作
5
Maple worksheet window
A.toolbar
B.Context barC.Section heading
D.Maple inputE.Maple output
F.Execution group
G.Section range bracket
H.Prompt
I.Symbol palette
J.Expression palette
K.Matrix palette
L.Vector palette
銘傳大學應用統計資訊學系 蔡桂宏 製作
6
Maple Help window
銘傳大學應用統計資訊學系 蔡桂宏 製作
7
Maple Help window
A.Help page nameB.toolbar
C.Help navigator Tabs
D.Topic folder
E.Bullet
F.Description
G.Help Page Title
H.Example
I.Also See
銘傳大學應用統計資訊學系 蔡桂宏 製作
8
Maple 9 Getting Started Guide
This guide contains an introduction to the graphical user interface and a tutorial that outlines using Maple to solve mathematical problems and create technical documents. It also contains additional information for new users about the help system, New User’s Tour, example worksheets and Maplesoft Web site.
銘傳大學應用統計資訊學系 蔡桂宏 製作
9
Maple 9 Learning Guide
This guide explains how Maple and the Maple language work. It describes the most important commands and uses them to solve technical problems. User hints for Maplet applications are also described in the guide.
銘傳大學應用統計資訊學系 蔡桂宏 製作
10
Maple 9 Introductory Programming Guide
This guide introduces the basic Maple programming concepts, such as expressions, data structures, looping and decision mechanisms, procedures, input and output, debugging, and the Maplet User Interface Customization System.
銘傳大學應用統計資訊學系 蔡桂宏 製作
11
Maple 9 Advanced Programming Guide
This guide extends the basic Maple programming concepts to more advanced topics, such as modules, graphics programming, and compiled code.
銘傳大學應用統計資訊學系 蔡桂宏 製作
12
Tutorials
Maple provides three tutorials that can be accessed from the New User submenu of the help menu: Full Tour Quick Tour Basic How To
銘傳大學應用統計資訊學系 蔡桂宏 製作
13
Websites
www.maplesoft.com Information on products, support, and services.
www.mapleapps.com Including a forum for sharing solutions, demon
strations, of Maple PowerTools, and an online tutorial
www.maple4students.com Includes course help, Maple tutorials, and Ma
ple graphics
銘傳大學應用統計資訊學系 蔡桂宏 製作
14
Tokens—Reserved Words(1)
Keywords Purpose
break, next loop control
if, then, elif, else if statement
for, from, in, by, to,for and while loops
while, do proc, local, global, option, error,
procedures
return options, description
export, module, use modules
end ends structures
銘傳大學應用統計資訊學系 蔡桂宏 製作
15
Tokens—Reserved Words(2)
Keywords Purpose
assuming assume facility
try, catch, finallyexception handling
read, saveread and save statements
quit, done, stop ending Maple
union, minus, intersect, subset
set operators
and, or, not, xor Boolean operators
impliesimplication operator
modmodulus operator
銘傳大學應用統計資訊學系 蔡桂宏 製作
16
Tokens—%operator
% last expression %% second-last expression %%% third-last expression
銘傳大學應用統計資訊學系 蔡桂宏 製作
17
Tokens—Binary Operator
Operator
MeaningOperator
Meaning
+ addition < less than
- subtraction <= less or equal
* multiplication > greater than
/ division >= greater or equal
^ exponentiation <> not equal
$ sequence operator -> arrow operator
@ composition union set union
@@ repeated composition minus set difference
&string neutral operatorintersect
set intersection
, expressiop separator ::type declaration, pattern binding
|| concatenation and logical and
.noncommutative multiplication or logical or
.. ellipsis xor exclusive or
mod modulo implies inplication:= assignment subset subset
銘傳大學應用統計資訊學系 蔡桂宏 製作
18
Tokens—Unary Operator
Operator
Meaning
+ unary plus(prefix)- unary minus(prefix)! factorial(postfix)$ sequence operator(prefix)not logical not(prefix)&string neutral operator(prefix). decimal point(prefix or postfix)%integer
label(prefix)
銘傳大學應用統計資訊學系 蔡桂宏 製作
19
Tokens—Initially known Name
Name Meaning Name Meaning
Catalan
Catalan's constantlasterror most recent error
constants
initially-known symbolic const.
libname
pathname of Maple library(ies)
Digitsnumber of digits in floating-point
NULLempty expression sequence
FAILcannot determine value
Ordertruncation order for series
false Boolean evaluation Pi mathematical constant
gamma
Euler's constantprintlevel
control display of information
I complex number true Boolean evaluation
infinity
mathematical infinityundefined
undefined
銘傳大學應用統計資訊學系 蔡桂宏 製作
20
Token – Concatenation Operator | |
String | | name String | | naturalInteger String | | string String | | (expression)
銘傳大學應用統計資訊學系 蔡桂宏 製作
21
Token – Escape Characters
? – Help procedure ! --Host operating system # -- Comment \ --continuation of lines and grouping
characters in a token.
銘傳大學應用統計資訊學系 蔡桂宏 製作
22
Selection Statements
if Boolean expression then statement sequenceelif Boolean expression then statement sequenceelse statement sequenceend if
銘傳大學應用統計資訊學系 蔡桂宏 製作
23
Repetition Statements
for name from expr by expr to expr while expr do
statement sequence
end do;
銘傳大學應用統計資訊學系 蔡桂宏 製作
24
1.1 Introduction
Understanding functions in Maple is also a good starting point for our discussions about Maple programming.
There are two distinct ways to represent mathematical functions in Maple. That is Maple expression ( := ) and a Maple function ( -> ).
銘傳大學應用統計資訊學系 蔡桂宏 製作
25
1.2 Functions in Mathematics
the formula has as its domain the set of all real numbers, its codomain is the set of all positive real numbers.
the formula has as its domain the set of all positive real numbers, its codomain is the set of all positive real numbers.
the formula has as its domain the set of all negative real numbers, its codomain is the set of all positive real numbers.
2)( xxf
2)( xxg
2)( xxh
銘傳大學應用統計資訊學系 蔡桂宏 製作
26
the function f is not invertible.
The inverse of the function g is .
The inverse of the function h is .
So f, g, and h all have the same formula (i.e., rule) but they are not the same function. The domain and codomain are important parts of the definition of a mathematical function.
xxg )()1(
xxh )()1(
銘傳大學應用統計資訊學系 蔡桂宏 製作
27
1.3 Functions in Maple
These two ways of representing mathematical functions are not equivalent. And it is subtle and non-obvious.
A Maple function is something defined using arrow notation ( ->).
A Maple expression is something defined using ( := ).x -> x^2;x -> a*x^2;(x,a) -> a*x^2;
銘傳大學應用統計資訊學系 蔡桂宏 製作
28
. Maple will treat all unassigned names (i.
e., all unknowns) as variables.
The mathematical function . g := x -> x^2 – 1; g(2);
g(x) := x^2-1; g(2);
cbxax 2
1)( 2 xxg
銘傳大學應用統計資訊學系 蔡桂宏 製作
29
g := cos + ln; k := x -> cos(x) + ln(x); g(Pi); k(Pi);
h := cos + (x -> 3*x-1); h(z);
銘傳大學應用統計資訊學系 蔡桂宏 製作
30
f := x -> (1 + x^2)/x^3; g := (1 + (x -> x^2))/(x -> x^3); h := (1 + (z -> z^2))/(y -> y^3);
f(1); g(1); h(1);
m := x -> (1 + exp(x))/x^3; n := (1 + exp)/(x -> x^3);
m(1); n(1);
銘傳大學應用統計資訊學系 蔡桂宏 製作
31
f := x^2; g := x -> 2 * x^3 * f; g(x); g(2);
f := x -> x^2; g := 2 * (x -> x^3) * f; g(x); g(2);
銘傳大學應用統計資訊學系 蔡桂宏 製作
32
1.4 Expressions vs. functions: Some puzzles
The following examples are meant to show that there are still a lot of subtle things to learn about variables and functions and how Maple handles them.
銘傳大學應用統計資訊學系 蔡桂宏 製作
33
Puzzle 1
f1 := x^2+1; f2 := y^2+1; f3 := f1 + f2; f3 is a function of two variables.
g1 := x -> x^2+1; g2 := y -> y^2+1; g3 := g1 + g2; g3(x); g3 is not a function of two variables.
銘傳大學應用統計資訊學系 蔡桂宏 製作
34
Puzzle 2
x:='x': a:=1: b:=2: c:=3: a*x^2+b*x+c; f := unapply( a*x^2+b*x+c, x ); g := x -> a*x^2+b*x+c; f(x); g(x); D(f); D(g);
p := x^2 + sin(x) + 1; p(2); p := unapply(p,x); p(2);
銘傳大學應用統計資訊學系 蔡桂宏 製作
35
Puzzle 3
plot( x^2, x=-10..10 );
plot( x->x^2, -10..10 );
plot( x^2, -10..10 ); plot( x->x^2, x=-10..10 );
銘傳大學應用統計資訊學系 蔡桂宏 製作
36
x := 5;
plot( x^2, x=-10..10 );
plot( x->x^2, -10..10 );
銘傳大學應用統計資訊學系 蔡桂宏 製作
37
Puzzle 4
f := x^2; f := x*f; f;
g := x -> x^2; g := x -> x*g(x); g(x);
銘傳大學應用統計資訊學系 蔡桂宏 製作
38
Puzzle 5
x^2; f := %; plot( f, x=-3..3 );
x^2; g := x -> %; plot( g, -3..3 );
銘傳大學應用統計資訊學系 蔡桂宏 製作
39
1.5 Working with expressions and Maple functions (review)
g := x -> x^2-3*x-10; g(x); g; print(g); eval(g); op(g);
銘傳大學應用統計資訊學系 蔡桂宏 製作
40
plot( a*x^2, -5..5 );
plot( x->a*x^2, -5..5 );
plot3d( (x,a)->a*x^2, -5..5, -10..10 );
銘傳大學應用統計資訊學系 蔡桂宏 製作
41
We wanted to evaluate our mathematical
function at a point, say at 1. f := x^2 - 3*x-10; g := x -> x^2-3*x-10;
subs( x=1, f ); eval( f, x=1 ); g(1);
f(1); subs( x=1, g );
銘傳大學應用統計資訊學系 蔡桂宏 製作
42
eval( f, x=1 ); subs( x=1, f ); Think of reading eval( f, x=1) as " evalua
te f at x=1" and think of reading subs (x=1,f) as " substitute x=1 into f".
factor( f ); factor( g(x) );
factor( f (x) ); factor( g );
銘傳大學應用統計資訊學系 蔡桂宏 製作
43
diff( f, x ); D( g ); diff command needed a reference to x in it
but the D command did not.
D( f ); diff( g, x );
銘傳大學應用統計資訊學系 蔡桂宏 製作
44
Let us do an example of combining two mathematical functions f and g by composing them to make a new function .
For the expression:
f := x^2 + 3*x; g := x + 1; h := subs( x=g, f ); subs(x=1, h);
))(()( xgfxh
銘傳大學應用統計資訊學系 蔡桂宏 製作
45
For the function:
f := x -> x^2 + 3*x; g := x -> x + 1; h := f@g; h(x); h(1);
銘傳大學應用統計資訊學系 蔡桂宏 製作
46
Example: representing a mathematical function of two variables.
f := (x^2+y^2)/(x+x*y); g := (x,y) -> (x^2+y^2)/(x+x*y); subs( x=1, y=2, f ); eval( f, {x=1, y=2} ); g(1,2);
simplify( f ); simplify( g(x,y) );
銘傳大學應用統計資訊學系 蔡桂宏 製作
47
Here is how we compute partial derivatives of the expression.
diff( f, x ); simplify( % ); diff( f, y ); simplify( % );
D[1](g); simplify( %(x,y) ); D[2](g); simplify( %(x,y) );
銘傳大學應用統計資訊學系 蔡桂宏 製作
48
1.6 Anonymous functions and expressions (review) Here we define an anonymous function an
d then evaluate, differentiate, and integrate it.
(z -> z^2*tan(z))(Pi/4);
x -> x^3 + 2*x;
%(2);
D( %% );
int( (%%%)(x), x );
銘傳大學應用統計資訊學系 蔡桂宏 製作
49
These next two commands show again that defining a function and naming a function are two distinct steps.
z -> z/sqrt(1-z);
f := %;
銘傳大學應用統計資訊學系 蔡桂宏 製作
50
f := ((x,y) -> x^2) + ((x,y) -> y^3); f(u,v); f(2,3);
g := (x -> x^2) + (y -> y^3); g(u,v); g(2,3);
銘傳大學應用統計資訊學系 蔡桂宏 製作
51
plot(w^3+1, w=-1..1);
plot( ((x,y)->x^3-y^3)(w,-1), w = -1..1 );
plot( w->(((x,y)->x^3-y^3)(w,-1)), -1..1 );
銘傳大學應用統計資訊學系 蔡桂宏 製作
52
1.7. Functions that return a function
f := a -> ( y->a*y ); f(3); f(3)(4);
銘傳大學應用統計資訊學系 蔡桂宏 製作
53
f := (x,y) -> 3*x^2+5*y^2; f(x,3);
fx3 := x -> f(x,3); fx3(x);
slice_f_with_y_fixed := c -> ( x->f(x,c) ); fx3 := slice_f_with_y_fixed(3); fx3(x);