y=polyval(p,x); %evaluate polynomial, defined by its vector of coefficients p1*x^n+...
Y=polyvalm(p,X); % evaluate with X matrix as a matrix (in polyval, get array)
z=roots(p); % from coeffs. find roots
p=poly(z); %from set of roots, z, construct polynomial
cp=poly(A); % characteristic polynomial, if we plug in matrix
polyvalm(cp,A); % should give zero
g = [1 -6 1 -8]; h = [1 -2];
[q,r]=deconv(g,h);% long division, gives quotient and remainder
conv(h,q); % should give back g
%--------------
x=linspace(-2,2,20);
y=1./(x+(1-x).^2);
p=polyfit(x,y,3);
plot(x,y,'*',x,polyval(p,x),'--')
%--------------
x=linspace(-2,2,20);
y=1./(x+(1-x).^2);
xx=linspace(-2,2,60);
yy=spline(x,y,yy);
plot(x,y,'*',xx,yy,'--')
%--------------
yi = interp1(x,y,xi) % nearest, linear, spline, cubic
x = [0 pi/4 3*pi/8 pi]; y = sin(x);
xi = linspace(0,pi,40)';
ys = interp1(x,y,xi,'spline');
yn = interp1(x,y,xi,'nearest');
yl = interp1(x,y,xi,'linear');
xx = linspace(0,pi,50);
plot(xx,sin(xx),'-',x,y,'.','MarkerSize',20), hold on
set(gca,'XTick',x), set(gca,'XTickLabel','0|pi/4|3pi/8|3pi/4|2pi')
set(gca,'XGrid','on')
h = plot(xi,ys,'x',xi,yn,'o',xi,yl,'+');
axis([-0.25 3.5 -0.1 1.1])
legend(h,'spline','nearest','linear'), hold off
%---------------
 INTERP2 2-D interpolation (table lookup).
    ZI = INTERP2(X,Y,Z,XI,YI) interpolates to find ZI, the values of the
    underlying 2-D function Z at the points in matrices XI and YI.
    Matrices X and Y specify the points at which the data Z is given.
    Out of range values are returned as NaN
 ZI = griddata(x,y,z,XI,YI,'linear')
GRIDDATA Data gridding and surface fitting.
    ZI = GRIDDATA(X,Y,Z,XI,YI) fits a surface of the form Z = F(X,Y)
    to the data in the (usually) nonuniformly-spaced vectors (X,Y,Z)
    GRIDDATA interpolates this surface at the points specified by
    (XI,YI) to produce ZI.  The surface always goes through the data
    points.  XI and YI are usually a uniform grid (as produced by
MESHGRID:  X and Y arrays for 3-D plots.
    [X,Y] = MESHGRID(x,y) transforms the domain specified by vectors
    x and y into arrays X and Y that can be used for the evaluation
    of functions of two variables and 3-D surface plots.
    The rows of the output array X are copies of the vector x and
    the columns of the output array Y are copies of the vector y.
 
    [X,Y] = MESHGRID(x) is an abbreviation for [X,Y] = MESHGRID(x,x).
    [X,Y,Z] = MESHGRID(x,y,z) produces 3-D arrays that can be used to
    evaluate functions of three variables and 3-D volumetric plots.
 
    For example, to evaluate the function  x*exp(-x^2-y^2) over the 
    range  -2 < x < 2,  -2 < y < 2,
 
        [X,Y] = meshgrid(-2:.2:2, -2:.2:2);
        Z = X .* exp(-X.^2 - Y.^2);
        mesh(Z)
TRI = DELAUNAY(X,Y,'sorted') assumes that the points X and Y are
    sorted first by Y and then by X, and that duplicate points have
    alr
     --------
x = rand(100,1)*4-2; y = rand(100,1)*4-2;
z = x.*exp(-x.^2-y.^2);
hi = -2:.1:2;
[XI,YI]=meshgrid(hi);
ZI = griddata(x,y,z,XI,YI,'cubic');
mesh(XI,YI,ZI), hold
plot3(x,y,z,'o'), hold off
---------------------------
GINPUT Graphical input from mouse.
    [X,Y] = GINPUT(N) gets N points from the current axes and returns 
    the X- and Y-coordinates in length N vectors X and Y.  The cursor
    can be positioned using a mouse (or by using the Arrow Keys on some 
    systems).  Data points are entered by pressing a mouse button
    or any key on the keyboard except carriage return, which terminates
    the input before N points are entered.
 
    [X,Y] = GINPUT gathers an unlimited number of points until the
    return key is pressed.
  
    [X,Y,BUTTON] = GINPUT(N) returns a third result, BUTTON, that 
    contains a vector of integers specifying which mouse button was
    used (1,2,3 from left) or ASCII numbers if a key on the keyboard
    was used.