// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab // Copyright (C) INRIA // Copyright (C) DIGITEO - 2012 - Allan CORNET // // This file must be used under the terms of the CeCILL. // This source file is licensed as described in the file COPYING, which // you should have received as part of this distribution. The terms // are also available at // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt function %r_p(h) if exists("with_texmacs")==1 & typeof(with_texmacs)=="function" then texout(h); else //used to display rational fraction with complex coefficients //The real case is hard coded if size(size(h),"*")>2 then //hypermatrix case %hmr_p(h) return end [m, n]=size(h); if (m == 0) | (n == 0) then return end del="!" blank=" " if m*n==1 then del=" ",end height=zeros(m,1) // to store "height" of each row do be displayed width=zeros(1,n) // to store "width" of each column do be displayed T=list() // to store display of each entry of the rational for k=1:n for l=1:m tlk=r2str(h(l,k)) height(l)=max(size(tlk,1),height(l)) width(k)=max(max(length(tlk)),width(k)) T($+1)=tlk end end ll=lines() k0=0 //manage column display while %t // find how many columns can be displayed simultaneously last=find(cumsum(width+2)[] then c(k1)=emptystr(1,size(k1,"*")),end // find coefficients with real AND imaginary part (to be parenthezied) kc=find(imag(coeff(p))<>0&real(coeff(p))<>0) w=ones(1,size(kc,"*")) if kc<>[] then c(kc)=lparen(w)+c(kc)+rparen(w),end // add formal variable name c=c+[emptystr(),v(ones(1:d))] // form exponents expo1=[" "," ",string(2:d)] //delete coeffiecients and exponents corresponding to "0"s c(kz)=[] expo1(kz)=[] if c==[] then c="0" expo1=emptystr() end // change coefficients sign display and adjust length of exponents le=0 expo=emptystr(c) for kc=1:size(c,"*") if kc>1 then if part(c(kc),1)<>"-" then c(kc)=" + "+c(kc), else c(kc)=" - "+part(c(kc),2:length(c(kc))) end end expo(kc)=part(blank,ones(1,length(c(kc))-le)) le=length(expo1(kc)) end expo=expo+expo1(1:size(c,"*")) //Handle long lines ll=lines() nn=size(expo,"*") txt=[] count=0 while %t L=cumsum(length(expo)) last=find(Ll2 then ll1=int((l1-l2)/2) ll2=l1-l2-ll1 b=blank(ones(size(t2,"*"),1)) txt=[t1; part(dash,ones(1,l1)); part(b,ones(1,ll1))+t2+part(b,ones(1,ll2))] elseif l1