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

« back to all changes in this revision

Viewing changes to macros/percent/%i_bezout.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 [g,u] = %i_bezout(a,b)
 
2
//   g = bezout(a,b) is the greatest common divisor of  a and b.   
 
3
//       a and b must contain non-negative   integer scalars.
 
4
//   [g,U] = bezout(a,b) also returns a (2x2) unimodular matrix U such that: 
 
5
//   [a,b]*U = [g,0].
 
6
//   These are useful for solving Diophantine equations and computing
 
7
//   Hermite transformations.
 
8
 
 
9
  it=max(inttype(a),inttype(b))
 
10
  a=iconvert(a,it);b=iconvert(b,it)
 
11
  u = [iconvert([1 0],it) a];
 
12
  v = [iconvert([0 1],it) b];
 
13
  zero=iconvert(0,it)
 
14
  while v(3)<>zero
 
15
    q = u(3)/v(3);
 
16
    t = u - v*q;
 
17
    u = v;
 
18
    v = t;
 
19
  end
 
20
  g = u(3);
 
21
  u=[u(1) -v(1);u(2) -v(2)]
 
22
 
 
23
endfunction