No BSD License  

Highlights from
Introduction à Matlab (deuxième édition)

from Introduction à Matlab (deuxième édition) by Jean-Thierry
tous les m-fichiers relatifs à la deuxième édition de l'Introduction à Matlab

plotsub3(textf, a, b, n)
function plotsub3(textf, a, b, n)

persistent rec

try
   textf = get(rec.f, 'string');
   a     = str2num(get(rec.a, 'string'));
   b     = str2num(get(rec.b, 'string'));
   n     = str2num(get(rec.n, 'string'));
catch
   if nargin < 1
      textf = 'sin(x)';
   end;
   if nargin < 2
      a = 0;
   end;
   if nargin < 3
      b = 15;
   end;
   if nargin < 4
      n = 1000;
   end;
end;
offset = 0.1;
x =  linspace(a, b, n);
f = inline(textf);
y =  feval(f, x); 
subplot('Position', [0.15, 0.3, 0.3, 0.3]); 
plot(x, y, 'y-'); 
title('\itfonction','fontsize',20);
axis([a, b, min(y),max(y)])
subplot('Position', [offset+0.5, 0.6, 0.3, 0.3]); 
yd =  diff(y)*n/(b-a); 
plot(x(1:end-1), yd, 'y-');
title('\itdrive','fontsize',20); 
axis([a, b, min(yd),max(yd)]);
subplot('Position', [offset+0.5, 0.1, 0.3, 0.3]); 
yp = cumtrapz(y)*(b-a)/n;
plot(x, yp, 'y-');
title('\itprimitive','fontsize',20);
axis([a, b, min(yp),max(yp)])
top = 0.90;
step=0.05;
width = 0.3;
width1 = 0.1;
beg = 0.01+offset;
uicontrol('Style', 'text',...
   'units', 'normalized',...
   'position',[beg,top,width1,step],...   
   'string','Fonction : ');
rec.f = uicontrol('Style', 'edit',...
   'units', 'normalized',...
   'position',[beg+width1,top,width,step],...   
   'string',textf);
uicontrol('Style', 'text',...
   'units', 'normalized',...
   'position',[beg,top-step,width1,step],...   
   'string','a : ')
rec.a =uicontrol('Style', 'edit',...
   'units', 'normalized',...
   'position',[beg+width1,top-step,width,step],...   
   'string',num2str(a));
uicontrol('Style', 'text',...
   'units', 'normalized',...
   'position',[beg,top-2*step,width1,step],...   
   'string','b : ')
rec.b = uicontrol('Style', 'edit',...
   'units', 'normalized',...
   'position',[beg+width1,top-2*step,width,step],...   
   'string',num2str(b));
uicontrol('Style', 'text',...
   'units', 'normalized',...
   'position',[beg,top-3*step,width1,step],...   
   'string','nb points : ')
rec.n = uicontrol('Style', 'edit',...
   'units', 'normalized',...
   'position',[beg+width1,top-3*step,width,step],...   
   'string',num2str(n));
top = 0.1;
uicontrol('Style', 'push',...
   'units', 'normalized',...
   'position',[beg,top,width1,2*step],...   
   'string', 'quitter',...
   'callback','delete(gcf);disp(''bye folks'');');
uicontrol('Style', 'push',...
   'units', 'normalized',...
   'position',[beg+width,top,width1,2*step],...   
   'string', 'retracer',...
   'callback','plotsub3');




Contact us at files@mathworks.com