~ubuntu-branches/ubuntu/karmic/scilab/karmic

« back to all changes in this revision

Viewing changes to macros/util/trisolve.sci

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function [b,sexp]=trisolve(a,b,sexp)
 
2
//[x [,sexp]] = trisolve(A,b [,sexp])  symbolically solves A*x =b 
 
3
// when A and b are matrices of character strings, A being assumed to be
 
4
// upper triangular.  
 
5
//sexp : vector of common subexpressions in A, b and x.
 
6
//!
 
7
//origine F. D. S. Steer INRIA 1989
 
8
//
 
9
// Copyright INRIA
 
10
[lhs,rhs]=argn(0)
 
11
[n0,m]=size(b)
 
12
if rhs==2 then
 
13
  for n=n0:-1:1
 
14
    pivot=a(n,n)
 
15
    for k=1:m,b(n,k)=ldivf(pivot,'('+b(n,k)+')'),end
 
16
    if n==1 then return,end
 
17
    for l=1:n-1
 
18
      for k=1:m,
 
19
        b(l,k)=addf(b(l,k),mulf(mulf('-1',a(l,n)),b(n,k)))
 
20
      end
 
21
    end
 
22
  end
 
23
else
 
24
  ns=prod(size(sexp))
 
25
  for n=n0:-1:1
 
26
    pivot=a(n,n)
 
27
    for k=1:m,
 
28
      ns=ns+1
 
29
      sexp(ns)=ldivf(pivot,'('+b(n,k)+')')
 
30
      b(n,k)='%('+string(ns)+')';
 
31
    end
 
32
    if n==1 then return,end
 
33
    for l=1:n-1
 
34
      for k=1:m,
 
35
        b(l,k)=addf(b(l,k),mulf(mulf('-1',a(l,n)),b(n,k)))
 
36
      end
 
37
    end
 
38
  end
 
39
end
 
40
 
 
41
 
 
42