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

Copyright 2001 by Robert M. Corless
All rights reserved

Useful one-word commands 

Использование монокоманд

Packages in Maple 

Пакеты в Maple

The MATLAB link 

Связь с MATLAB

> restart;

> with( Matlab );

> with( LinearAlgebra ):
> Digits := trunc( evalhf(Digits) );

Digits := 14

> evalM( " x=linspace(0,pi,1024) " );
> evalM( " v=sin(50*x)+0.1*sin(200*x)+0.5*sin(500*x)+0.00001*rand(1,1024) " );
> V := getvar( "v" );

V := _rtable[14252108]

> p := fft( V );

p := _rtable[4383912]

> Spectrum := map( abs, p ):
> plot( [seq( [2*(k-1)/1024,log[10](Spectrum[k])], k=1..512 )],
style=POINT, colour=black, axes=BOXED );

> evalM( "p = fft(v)" );

> evalM( "semilogy( x(1:512), abs(p(1:512)) )" );

> restart;

> with( Matlab );
> p := expand( (t-1.99)*(t-3.0)*(t-1) );

p := t^3-5.99*t^2-5.970+10.960*t

> q := expand( (t+1)*(t-2.01) );

q := t^2-1.01*t-2.01

> N := 3;

N := 3

> p1 := p + add( x(i)*t^(i-1), i=1..N );

p1 := t^3-5.99*t^2-5.970+10.960*t+x(1)+x(2)*t+x(3)*...

> q1 := q + add( x(i+N)*t^(i-1), i=1..N-1 );

q1 := t^2-1.01*t-2.01+x(4)+x(5)*t

> constraint := resultant( p1, q1, t );

> unconstrained := add( x(i)^2, i=1..2*N-1 ) + 1.0e30*constraint^2:
> fd := fopen( "C:/books/ess/programs/unconstrained.m", WRITE );
fprintf( fd, "function y = unconstrained(x)\n" );
fprintf( fd, "y=%a;\n", unconstrained );
fprintf( fd, "end;\n" );
fclose( fd );

fd := 0

30

813

5

> evalM( "path('C:\\books\\ess\\programs',path)" );
> initialguess := [seq(0.,k=0..2*N-1)];

initialguess := [0., 0., 0., 0., 0., 0.]

> mstring := sprintf( "pert = fminsearch( @unconstrained, %a, optimset('TolX',1.0e-14) )", initialguess ) ;

> evalM( mstring );

> ans := getvar( "pert" );

> subs( seq(x(i)=ans[i],i=1..2*N), [unconstrained,constraint] );

[.2272691301e30, .4767275219]

> subs( seq(x(i)=initialguess[i],i=1..2*N), [unconstrained,constraint] );

[.2288208272e30, .47835220]

> perturbed := subs( seq(x(i)=ans[i],i=1..2*N), [p1,q1] );

> fsolve( perturbed[1], t, complex );

1.000000040, 1.989999758, 3.000000250

> fsolve( perturbed[2], t, complex );

-.9999912938, 2.009931981

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

 
Hosted by uCoz