Comandos Úteis e Simples
Seção 2.8: Os Pacotes do Maple
Session 2.8.1: O link MATLAB
| > | restart; |
| > | with( Matlab ); |
| > | with( LinearAlgebra ): |
| > | Digits := trunc( evalhf(Digits) ); |
| > | 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" ); |
| > | p := fft( V ); |
| > | 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) ); |
| > | q := expand( (t+1)*(t-2.01) ); |
| > | N := 3; |
| > | p1 := p + add( x(i)*t^(i-1), i=1..N ); |
| > | q1 := q + add( x(i+N)*t^(i-1), i=1..N-1 ); |
| > | 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 ); |
| > | evalM( "path('C:\\books\\ess\\programs',path)" ); |
| > | initialguess := [seq(0.,k=0..2*N-1)]; |
| > | 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] ); |
| > | subs( seq(x(i)=initialguess[i],i=1..2*N), [unconstrained,constraint] ); |
| > | perturbed := subs( seq(x(i)=ans[i],i=1..2*N), [p1,q1] ); |
| > | fsolve( perturbed[1], t, complex ); |
| > | fsolve( perturbed[2], t, complex ); |
| > |
| > |