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

« back to all changes in this revision

Viewing changes to macros/calpol/horner.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:
11
11
//!
12
12
//
13
13
// Copyright INRIA
14
 
if type(p)==16 then r=horner(p(2),x)./horner(p(3),x),return,end
15
 
if type(p)==129 then
16
 
  p=horner(p(:),x);p=p(1):p(2):p(3)
17
 
end
18
 
[m,n]=size(p)
19
 
if m==-1 then indef=%t,m=1,n=1,p=p+0;else indef=%f,end
20
 
r=[]
21
 
for l=1:m
22
 
  rk=[]
23
 
  for k=1:n
24
 
   plk=p(l,k)
25
 
   d=degree(plk)
26
 
   rlk=coeff(plk,d)*ones(x); // for the case horner(1,x)
27
 
   for kk=1:d,
28
 
     rlk=rlk.*x+coeff(plk,d-kk);
29
 
   end;
30
 
   rk=[rk rlk]
 
14
  tp=type(p)
 
15
  if tp<=10 then
 
16
    [m,n]=size(p)
 
17
    if m==-1 then indef=%t,m=1,n=1,p=p+0;else indef=%f,end
 
18
    if m*n==1 then //special case for a single polynomial
 
19
      C=coeff(p)
 
20
      r=C($)*ones(x)
 
21
      for kk=degree(p):-1:1,r=r.*x+C(kk);end;
 
22
    else
 
23
      r=[]
 
24
      for l=1:m
 
25
        rk=[]
 
26
        for k=1:n
 
27
          plk=p(l,k)
 
28
          d=degree(plk)
 
29
          rlk=coeff(plk,d)*ones(x); // for the case horner(1,x)
 
30
          for kk=1:d,
 
31
            rlk=rlk.*x+coeff(plk,d-kk);
 
32
          end;
 
33
          rk=[rk rlk]
 
34
        end
 
35
        r=[r;rk]
 
36
      end
 
37
    end
 
38
    if indef then r=r*eye(),end
 
39
  elseif tp==16 then 
 
40
    r=horner(p(2),x)./horner(p(3),x),
 
41
  elseif tp==129 then
 
42
    r=horner(p(:),x);r=r(1):r(2):r(3)
31
43
  end
32
 
  r=[r;rk]
33
 
end
34
 
if indef then r=r*eye(),end
 
44
endfunction