~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to macros/percent/%i_gcd.sci

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function [x,uu]=%i_gcd(p)
 
2
//Given a polynomial vector p, [pgcd,u]=gcd(p) computes the gcd 
 
3
//of components and a unimodular matrix (with polynomial inverse) u, 
 
4
//with minimal degree such that [p1 p2]*u=[0 ... 0 pgcd]
 
5
//!
 
6
// Copyright INRIA
 
7
  [lhs,rhs]=argn(0)
 
8
  [m,n]=size(p);it=inttype(p)
 
9
  mn=m*n
 
10
  p=matrix(p,1,mn)
 
11
  x=p(1);
 
12
  uu=iconvert(1,it)
 
13
  for l=2:mn,
 
14
    [x,u]=bezout(x,p(l)),
 
15
    if lhs==2 then
 
16
      uu=[uu(:,1:l-2) uu(:,l-1)*u(1,[2 1])];uu(l,l-1:l)=u(2,[2 1]);
 
17
    end
 
18
  end,
 
19
  if lhs==1 then return,end
 
20
  for l=mn:-1:2
 
21
    pivot=uu(l,l-1);
 
22
    for k=l:mn
 
23
      q=uu(l,k)/pivot
 
24
      r=uu(l,k)-q*pivot
 
25
      if q<>iconvert(0,it) then
 
26
        uu(1:l-1,k)=uu(1:l-1,k)-q*uu(1:l-1,l-1)
 
27
        uu(l,k)=r;
 
28
      end
 
29
    end
 
30
  end
 
31
endfunction