[scilab-Users] How to define set of numbers without some special numbers?

harishankar ramachandran hsr at ee.iitm.ac.in
Fri May 22 07:32:06 CEST 2009


Let us say you have already defined a function f(x), and you want to plot it 
over a range excluding some special points, {x_i}

    a < x_1 < x_2 <...< x_k < b

There is no built in function in scilab that plots this. However, it is a 
simple matter to create plots that skip these points. User dependent issues:

1. Should the points on either side of a special point be connected?

2. Should the points on either side of a special point be equi-distant?

Given that info, it is a simple matter to create the set of disjoint line 
segments that can be used to plot the function (using xpoly) Here is a 
function that connects across special points, but ensures points on either 
side are _roughly_ equidistant:

=================================
//* program to plot a function excluding a set of given points
function plote2d(a,b,exclude,n,f,optarg)
  //* the range is a to b
  //* exclude is a vector containing the points to exclude
  //* n is the total number of points to use
  //* f is the function to be invoked
  dx=(b-a)/(n-1); // the nominal spacing between points
  x0=[a; matrix(exclude,length(exclude),1); b];
  nn=ceil(diff(x0)/dx);
  j=0;
  xx=zeros(sum(nn),1);
  for i=1:length(nn)
    // printf("%d: (%f,%f)\n",nn(i),x0(i),x0(i+1));
    t=linspace(x0(i),x0(i+1),nn(i)+2)';
    xx(j+1:j+nn(i))=t(2:$-1);
    j=j+nn(i);
  end
  yy=f(xx);
  if isdef("optarg")
    s="plot2d(xx,yy,"+optarg+")";
    execstr(s);
  else
    plot2d(xx,yy)
  end
endfunction
function y=f(x)
  y=abs(log((x-1).^2)+log((x+0.5).^2));
endfunction

//* test code
clf
plote2d(-2,2,[-1 -0.5 1 1.5],501,f,'logflag=''nl''')
xtitle("a sample plot");
//* comments
// if singularities are too close to each other, we might end up 
// with exactly one point between singularities.

// also, 'n' is a nominal number. The number of points actually
// used may slightly exceed n.

// The lines are connected across the singularities.

// Note that optional arguments are sent as a quoted string.
// Embedded quotes are handled by doubling them (see test code).
=================================

hari

On Thursday 21 May 2009 14:14, Christian Hoehle wrote:
> Hi all,
>
> i recently tried to do a plot of a function with a value range of (x |
> (-100 <= x <= 100) \ {0; -3; 2}).
> Any idea how to realize that?
> Most probably i just didn't find the manual's page describing definition
> of sets omitting special numbers... or yust didn't get the right keyword
> to search for ;-)
>
> Thanks for all hints.
>
> Cheers,
> Chris

-- 
Dr. Hari Ramachandran, Professor, 332B ESB, EE Dept, IIT-Madras
Interests: Nonlinear Optics, Nonlinear Waves, Plasma Physics, Particle 
           Simulations, Computational Algorithms, Linux.
Off: 91-44-2257-4421                    Fax: 91-44-2257-0120
Res: 91-44-2663-1863             Home Email: omkarbharathi at gmail.com



More information about the users mailing list