// Formas de onda de un sistema de primer orden. // Autor: Juan Claudio Regidor // Versi—n: 1.1 // Fecha: 27/may/02 // title "Sistema de primer orden" help {@ Formas de onda de un sistema de primer orden. @} variable tau // ctte. de tiempo variable imp variable recta variable w init (tau, imp, recta) = init menu "Respuesta al escal—n" _checkmark(imp == 0) imp = newgr(imp) menu "Mostrar pendiente" _checkmark(recta == 1) recta = newgr(recta) separator menu "800x600" _checkmark(w == 1) w = graf_layout(1) menu "1024x768" _checkmark(w == 2) w = graf_layout(2) menu "1152x768" _checkmark(w == 3) w = graf_layout(3) figure "Respuesta primer orden" draw exponencial(0, 10, tau, imp, recta) figure "Valor de tau" draw tau_sel(tau) mousedrag (tau) = dragSlider(tau, _nb, _x1) functions {@ function (tau, imp, recta) = init tau = 2; imp = 1; recta = 0; graf_layout(0); function w1 = graf_layout(w) w1 = w; switch w case 0 x = 510; y = 400; case 1 x = 800; y = 600; case 2 x = 1024; y = 768; case 3 x = 1152; y = 768; end x=x-26;y=y-80; ux=x/8; uy=y/8; uy3 = 10; subplots('Respuesta primer orden\nValor de tau'); subplotpos([0,ux,0,uy-uy3; 0,ux,uy-uy3,uy]); function (gr) = newgr(gr) gr = 1 - gr; function exponencial(tmin, tmax, tau, imp, recta) scale([tmin, tmax, -0.05, 1.05]); //plotoption xgrid; //plotoption ygrid; line([0, 1], 1, '-'); line([0, 1], 0); (t, x) = sigExp(tmin, tmax+1, 0, tau, false); if(imp == 1) plot(t, x, 'b'); text(5, 0.8, 'exp(-t/tau)', 'lb'); else plot(t, 1 - x, 'b') text(5, 0.2, '1 - exp(-t/tau)', 'lb'); end; line([1, 0], 0); if(recta == 1) if(imp == 1) line([1/tau, 1], 1, 'r'); line([0, 1], exp(-1), 'g-'); text(10, exp(-1)+0.02, '0,368', 'rb'); else line([-1/tau, 1], 0, 'r'); line([0, 1], 1-exp(-1), 'g-'); text(10, 1-exp(-1)+0.02, '0,632', 'rb'); end line([1, 0], tau, 'g-'); text(tau+0.05, 0.05,'t=tau', 'l'); end; function tau_sel(tau) settabs('tau = 0.00 \t'); slider(sprintf('tau = %.2f', tau), [tau], [0, 5], '', '', 1); function (tau) = dragSlider(tau, nb, x1) if isempty(nb) cancel; end tau = x1; function (t, x) = sigExp(tmin, tmax, t0, tau, backward) n = (tau > .2)? 200 : 400; if backward if t0 > tmax t = tmin + (tmax - tmin) * (0:n) / n; x = exp((t - t0) / tau); elseif t0 < tmin t = [tmin, tmax]; x = [0, 0]; else t = [tmin+(t0-tmin)*(0:n)/n, t0, tmax]; x = [exp((tmin+(t0-tmin)*(0:n)/n-t0)/tau), 0, 0]; end else if t0 < tmin t = tmin + (tmax - tmin) * (0:n) / n; x = exp((t0 - t) / tau); elseif t0 > tmax t = [tmin, tmax]; x = [0, 0]; else t = [tmin, t0, t0+(tmax-t0)*(0:n)/n]; x = [0, 0, exp((t0-(t0+(tmax-t0)*(0:n)/n))/tau)]; end end @}