File: interpln.sci

package info (click to toggle)
scilab 2.4-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 55,196 kB
  • ctags: 38,019
  • sloc: ansic: 231,970; fortran: 148,976; tcl: 7,099; makefile: 4,585; sh: 2,978; csh: 154; cpp: 101; asm: 39; sed: 5
file content (43 lines) | stat: -rw-r--r-- 909 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function [y]=interpln(xyd,x)
//Given a set of points in the plane with coordinates xyd and a set of 
//x points 
// [y]=interpln(xyd,x) allows to compute a set of y obtained by linear interpolation.
//% parameters
//  xyd :  coordinates of points (2 rows matrix)
//        first row : x
//        second row : y
//  x   : vector of x's for which y is wanted
//  y   : vector of y computed.
//!
// S Steer INRIA 1991

// Copyright INRIA
[md,nd]=size(xyd);
if md<>2 then
  error('interpln:xyd must have two rows!')
end
//

n=size(x,'*');
d=xyd(:,1:nd-1)-xyd(:,2:nd);
k=find(abs(d(1,1:nd-1))==0)
if k<>[] then
  d(1,k)=%eps*ones(k)
  xyd(1,k+ones(k))=xyd(1,k)+%eps*ones(k);
end
d=d(2,:)./d(1,:);
for pt=1:n,
  xpt=x(pt);
  k=find(xpt>xyd(1,1:nd-1)&xpt<=xyd(1,2:nd));
  if k==[] then
    if xpt<=xyd(1,1) then k=1,else k=nd-1,end
  else
    k=k(size(k,'*'));
  end
  y(1,pt)=xyd(2,k)+(xpt-xyd(1,k))*d(k)
end