Manual Maple 2.8.1.mws

Comandos Úteis e Simples

Seção 2.8: Os Pacotes do Maple

Session 2.8.1: O link  MATLAB

>    restart;

>    with( Matlab );

[chol, closelink, defined, det, dimensions, eig, evalM, fft, getvar, inv, lu, ode45, openlink, qr, setvar, size, square, transpose]

>    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 := Vector(%id = 13933704)

>    p := fft( V );

p := Vector(%id = 13933744)

>    Spectrum := map( abs, p ):

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

[Maple Plot]

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

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

>    restart;

>    with( Matlab );

[chol, closelink, defined, det, dimensions, eig, evalM, fft, getvar, inv, lu, ode45, openlink, qr, setvar, size, square, transpose]

>    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)*t^2

>    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 );

constraint := 5.0401*x(3)*x(1)+5.99*x(5)*x(4)^2-2.0301*x(3)*x(2)+1.*x(2)*x(5)^2*x(4)+8.95*x(4)*x(1)+.47835220-23.939998*x(1)-48.059202*x(2)-96.6591900*x(3)-8.1152120*x(4)-15.7928280*x(5)-10.97*x(4)^2*x...
constraint := 5.0401*x(3)*x(1)+5.99*x(5)*x(4)^2-2.0301*x(3)*x(2)+1.*x(2)*x(5)^2*x(4)+8.95*x(4)*x(1)+.47835220-23.939998*x(1)-48.059202*x(2)-96.6591900*x(3)-8.1152120*x(4)-15.7928280*x(5)-10.97*x(4)^2*x...
constraint := 5.0401*x(3)*x(1)+5.99*x(5)*x(4)^2-2.0301*x(3)*x(2)+1.*x(2)*x(5)^2*x(4)+8.95*x(4)*x(1)+.47835220-23.939998*x(1)-48.059202*x(2)-96.6591900*x(3)-8.1152120*x(4)-15.7928280*x(5)-10.97*x(4)^2*x...
constraint := 5.0401*x(3)*x(1)+5.99*x(5)*x(4)^2-2.0301*x(3)*x(2)+1.*x(2)*x(5)^2*x(4)+8.95*x(4)*x(1)+.47835220-23.939998*x(1)-48.059202*x(2)-96.6591900*x(3)-8.1152120*x(4)-15.7928280*x(5)-10.97*x(4)^2*x...
constraint := 5.0401*x(3)*x(1)+5.99*x(5)*x(4)^2-2.0301*x(3)*x(2)+1.*x(2)*x(5)^2*x(4)+8.95*x(4)*x(1)+.47835220-23.939998*x(1)-48.059202*x(2)-96.6591900*x(3)-8.1152120*x(4)-15.7928280*x(5)-10.97*x(4)^2*x...
constraint := 5.0401*x(3)*x(1)+5.99*x(5)*x(4)^2-2.0301*x(3)*x(2)+1.*x(2)*x(5)^2*x(4)+8.95*x(4)*x(1)+.47835220-23.939998*x(1)-48.059202*x(2)-96.6591900*x(3)-8.1152120*x(4)-15.7928280*x(5)-10.97*x(4)^2*x...
constraint := 5.0401*x(3)*x(1)+5.99*x(5)*x(4)^2-2.0301*x(3)*x(2)+1.*x(2)*x(5)^2*x(4)+8.95*x(4)*x(1)+.47835220-23.939998*x(1)-48.059202*x(2)-96.6591900*x(3)-8.1152120*x(4)-15.7928280*x(5)-10.97*x(4)^2*x...

>    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 ) ;

mstring :=

>    evalM( mstring );

>    ans := getvar( "pert" );

ans := _rtable[13933704]
ans := _rtable[13933704]

>    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] );

perturbed := [t^3-5.990000048*t^2-5.970000012+10.95999998*t, t^2-1.009940687*t-2.009914482]

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

1.000000040, 1.989999758, 3.000000250

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

-.9999912938, 2.009931981

>   

>