Robert M. Corless
Department of Applied Mathematics
University of Western Ontario
London, Canada

Copyright 2001 by Robert M. Corless
All rights reserved

Programming in Maple 

Программирование в Maple

Operators and modules 

Операторы и модули

> restart;
> eval( diff(f(x),x), x=3 );

eval(diff(f(x),x),{x = 3})

> restart;
> f := t -> t*sin(t) ;

f := proc (t) options operator, arrow; t*sin(t) end...

> f(0);

0

> f(x^2+a);

(x^2+a)*sin(x^2+a)

> D(f);

proc (t) options operator, arrow; sin(t)+t*cos(t) e...

> g := (t::complex(numeric)) -> t*arcsin(t) ;

g := proc (t::complex(numeric)) options operator, a...

> g(0);

0

> g(x);
Error, invalid input: g expects its 1st argument, t, 
to be of type complex(numeric), but received x
> g(1+I);

(1+I)*arcsin(1+I)

> g(1.+I);

-.3950356295+1.727514494*I

> g( 2. );

3.141592654-2.633915794*I

> g( 2.+0.*I );

3.141592654+2.633915794*I

> g( 2.-0.*I );

3.141592654-2.633915794*I

> restart;

> Aye := f -> unapply(int(f(x),x),x);

Aye := proc (f) options operator, arrow; unapply(in...

> Aye( t->t^2 );

proc (x) options operator, arrow; 1/3*x^3 end proc

> Aye( t->1/t );

ln

> t -> sin(t);

sin

> x -> 4;

4

> 4(3);

4

> 2(anything);

2

> 2(a+b);

2

> restart;
> series( f(x), x=a, 4 );

> D(g(h));

D(g(h))

> D( g@h );

`@`(D(g),h)*D(h)

> D(g*h);

D(g)*h+g*D(h)

> D(h) := 0;

D(h) := 0

> D(x) := 1;

D(x) := 1

> D(F@x);

`@`(D(F),x)

> D(x^2);

2*x

> D(g^2);

2*D(g)*g

> restart;
> interface(imaginaryunit=j);
> finite_differences := proc( h::{name,complex(numeric)} )
description "Generator for finite difference"
" operators with step size h ";
module()
export I, E, Delta, delta, S;
local t, x, k, N;
E := f -> (x->f(x+h));
Delta := f -> (t->((E(f)(t)-f(t))/h));
delta := f -> (x -> (f(x+h)-f(x-h))/(2*h) );
I := f -> unapply( int(f(t), t=0..x), x );
S := f -> unapply( sum(f(k*h), k=1..N), N );
end module;
end proc:
> hop := finite_differences( epsilon );

hop := module () local t, x, k, N; export I, E, Del...

> with( hop );

[Delta, E, I, S, delta]

> esin := E(sin);

esin := proc (x) options operator, arrow; sin(x+eps...

> esin( phi );

sin(phi+epsilon)

> E( esin );

proc (x) options operator, arrow; esin(x+epsilon) e...

> E( esin )(a);

sin(a+2*epsilon)

> (E@@2)(sin);

proc (x) options operator, arrow; proc (x) options ...

> (E@@3)(sin)(a);

sin(a+3*epsilon)

> F := I( sin );

F := proc (x) options operator, arrow; -cos(x)+1 en...

> D( F );

sin

> DeltaF := Delta( F );

DeltaF := proc (t) options operator, arrow; (E(F)(t...

> DelF := DeltaF( t );

DelF := (-cos(t+epsilon)+cos(t))/epsilon

> limit( DelF, epsilon = 0 );

sin(t)

> S( m->m^2 );

proc (N) options operator, arrow; 1/3*epsilon^2*(N+...

> sinsum := S( n->sin(n*Pi) );

> sinsum( m );

> combine( %, trig );

(-sin(epsilon*Pi*m)+sin(epsilon*Pi*m+epsilon*Pi)-si...

> eval( %, epsilon=1/m );

-2*sin(1/m*Pi)/(2*cos(1/m*Pi)-2)

> limit( %%, epsilon = 0 );

0

С официального разрешения                    © 2002 Waterloo Maple, Inc

 
Hosted by uCoz