next up previous
Next: ODE'S and DAE's Up: Scilab to Fortran translator Previous: Operation with complex numbers

Matrix divisions

Source code of Scilab function

function x=t6(a,b)
c=b*b,
x=(a/b)/2+2/c,

Translation procedure

-->lt=list();
-->lt(1)=list('1','na','ma');
-->lt(2)=list('1','ma','ma');

-->// show the initial data
-->printspecs(t,lt)
| variable number    | fortran type    |# rows     |# columns    |
|1                   |double precision |na         |ma           |
|2                   |double precision |ma         |ma           |
-->//translate
-->txt=sci2for(t,'t',lt);
Generated Fortran code
       subroutine t(a,b,x,na,ma,work,iwork,ierr)
c!
c automatic translation
c
c!     calling sequence
c      ----------------
c
c      a          : double precision variable of size na,ma
c      b          : double precision variable of size ma,ma
c      x          : double precision variable of size na,ma
c      na         : integer variable
c      ma         : integer variable
c      work  : working array :
c              ma*ma+ma*ma+ma+ma+ma*ma
c      iwork : working array :
c              ma+na*ma+ma
c      ierr : error
c             0 :  correct run
c             1 : singular b matrix
c             2 : singular work(iwc) matrix
c
c      dimension of local variables
c      -----------------------------
c!
       double precision a(na,ma),b(ma,ma),x(na,ma),c(ma,ma),work(*)
       integer na,ma,iwork(*)
c
c      adress of local variables
       iwc = 1
c
       iw0 = iwc+ma*ma
       iiw0 = 1
c
       call dmmul(b,ma,b,ma,work(iwc),ma,ma,ma,ma)
c
       iw1 = iw0+ma*ma
       iw2 = iw1+ma*ma
       iw3 = iw2+ma
       call dcopy(ma*ma,b,1,work(iw1),1)
       call dgefa(work(iw1),ma,ma,iwork(iiw0),ierr)
       if(ierr.ne.0) then
          ierr=1
          return
       endif
       call dgesl(work(iw1),ma,ma,iwork(iiw0),work(iw0),0)
       call dcopy(na*ma,work(iw0),1,iwork(iiw1),1)
       call dscal(na*ma,1.0d0/2,iwork(iiw1),1)
       call dcopy(ma*ma,work(iwc),1,work(iw0),1)
       iw4 = iw3+ma
       iiw3 = iiw2+ma
       call dgefa(work(iw0),ma,ma,iwork(iiw2),ierr)
       if(ierr.ne.0) then
          ierr=2
          return
       endif
       call dgedi(work(iw0),ma,ma,iwork(iiw2),w,work(iw3),1)
       call dcopy(na*ma,iwork(iiw1),1,x,1)
       call dadd(na*ma,x,1,work(iw0),1)
c
       return
c
       end



Scilab group