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

Returning more than one result 

Вывод более чем одного результата

> restart;
> mynormal := proc( p::polynom, q::polynom, x::name, GCD )
local g, pc, qc; g := gcd(p, q); if nargs > 3 and type( GCD, name ) then
GCD := g; end if: rem( p, g, x, pc ); rem( q, g, x, qc ); pc, qc end:
> (num, den) := mynormal( 1+s, 1+2*s+s^2, s );

num, den := 1, 1+s

> (num, den) := mynormal( 1+s, 1+2*s+s^2, s, 'g' );

num, den := 1, 1+s

> g;

1+s

> P := expand( (x+1)^3*(x+2)^2*(x+3) );

P := x^6+10*x^5+40*x^4+82*x^3+91*x^2+52*x+12

> Q := diff( P, x );

Q := 6*x^5+50*x^4+160*x^3+246*x^2+182*x+52

> (num, den) := mynormal( P, Q, x, g );

num, den := x^3+6*x^2+11*x+6, 6*x^2+26*x+26

> g;

1+s

> (num, den) := mynormal( P, Q, x, 'g' );

num, den := x^3+6*x^2+11*x+6, 6*x^2+26*x+26

> g;

x^3+4*x^2+5*x+2

> mynormal2 := proc( p::polynom, q::polynom, x::name, GCD )
local g, pc, qc;
g := gcd(p, q);
if nargs > 3 then
try
GCD := g;
catch :
error "I'm very sorry, I cannot assign to \"%1\"", GCD ;
end try;
end if:
rem( p, g, x, pc );
rem( q, g, x, qc );
pc, qc
end:
> G := "Something we need.";

G :=

> mynormal2( P, Q, x, G );
Error, (in mynormal2) I'm very sorry, 
I cannot assign to "Something we need."
> G;

> mynormal2( P, Q, x, 'G' );

x^3+6*x^2+11*x+6, 6*x^2+26*x+26

> G;

x^3+4*x^2+5*x+2

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

 
Hosted by uCoz