cleaning demos graphics, cacsd, differential_equations 35/1935/2
Allan CORNET [Wed, 15 Sep 2010 14:48:59 +0000 (16:48 +0200)]
Change-Id: Ic7c025c2ce12b8e93c128fe2e78ebbc110c32f8e

226 files changed:
scilab/contrib/toolbox_skeleton/demos/c_sum.dem.sce
scilab/contrib/toolbox_skeleton/demos/cpp_find.dem.sce
scilab/contrib/toolbox_skeleton/demos/fortran_sum.dem.sce
scilab/contrib/toolbox_skeleton/demos/scilab_sum.dem.sce
scilab/modules/cacsd/demos/cacsd.dem.gateway.sce
scilab/modules/cacsd/demos/cont.dem
scilab/modules/cacsd/demos/flat/car.dem.sce
scilab/modules/cacsd/demos/flat/car.sci
scilab/modules/cacsd/demos/flat/demo_car_eng.htm [deleted file]
scilab/modules/cacsd/demos/flat/demo_car_fr.htm [deleted file]
scilab/modules/cacsd/demos/flat/demo_truck_eng_htm [deleted file]
scilab/modules/cacsd/demos/flat/demo_truck_fr.htm [deleted file]
scilab/modules/cacsd/demos/flat/flat.dem.gateway.sce
scilab/modules/cacsd/demos/flat/truck.dem.sce
scilab/modules/cacsd/demos/flat/truck.sci
scilab/modules/cacsd/demos/lqg/lqg.dem
scilab/modules/cacsd/demos/lqg/lqg2.dem
scilab/modules/cacsd/demos/lqg/scheme.dem
scilab/modules/cacsd/demos/mixed.dem
scilab/modules/cacsd/demos/pendulum/graphics.sci
scilab/modules/cacsd/demos/pendulum/pendule.dem
scilab/modules/cacsd/demos/pendulum/simulation.sci
scilab/modules/cacsd/demos/pid.dem
scilab/modules/demo_tools/macros/demo_gui.sci
scilab/modules/demo_tools/macros/demo_viewCode.sci
scilab/modules/differential_equations/demos/bike/bike.dem.gateway.sce
scilab/modules/differential_equations/demos/bike/macros/velo1.sci
scilab/modules/differential_equations/demos/bike/macros/velo2.sci
scilab/modules/differential_equations/demos/dae/dae.dem.gateway.sce
scilab/modules/differential_equations/demos/dae/dae1/pend3d1.dem.sce
scilab/modules/differential_equations/demos/dae/dae2/dae2.dem.gateway.sce
scilab/modules/differential_equations/demos/dae/dae2/demo_sliding_pendulum.sci
scilab/modules/differential_equations/demos/dae/dae2/demo_sliding_pendulum_fr.htm [deleted file]
scilab/modules/differential_equations/demos/dae/dae2/pendg.sci
scilab/modules/differential_equations/demos/dae/dae2/pendg1.dem.sce
scilab/modules/differential_equations/demos/dae/dae2/pendg2.dem.sce
scilab/modules/differential_equations/demos/flow/blackhole_interface.sci
scilab/modules/differential_equations/demos/flow/cylinder.sci
scilab/modules/differential_equations/demos/flow/cylinder_interface.sci
scilab/modules/differential_equations/demos/flow/flow.dem.gateway.sce
scilab/modules/differential_equations/demos/flow/sphere_interface.sci
scilab/modules/differential_equations/demos/n_pendulum/n_pendulum.dem.sce
scilab/modules/differential_equations/demos/n_pendulum/n_pendulum.sci
scilab/modules/differential_equations/demos/ode/ode.dem.gateway.sce
scilab/modules/differential_equations/demos/ode/ode_1dvect/ode_1dvect.dem.sce
scilab/modules/differential_equations/demos/ode/ode_chimpl/ode_chimpl.dem.sce
scilab/modules/differential_equations/demos/ode/ode_chstiff/ode_chstiff.dem.sce
scilab/modules/differential_equations/demos/ode/ode_lorentz/ode_lorentz.dem.sce
scilab/modules/differential_equations/demos/ode/ode_lotka/ode_lotka.dem.sce
scilab/modules/differential_equations/demos/ode/ode_simple/ode_simple.dem.sce
scilab/modules/differential_equations/demos/ode/ode_vanderpol/ode_vanderpol.dem.sce
scilab/modules/differential_equations/demos/simulation.dem.gateway.sce
scilab/modules/differential_equations/demos/wheel/wheel.dem.gateway.sce
scilab/modules/differential_equations/demos/wheel/wheel1.dem.sce
scilab/modules/differential_equations/demos/wheel/wheel2.dem.sce
scilab/modules/differential_equations/demos/wheel/wheel_show.sci
scilab/modules/dynamic_link/demos/dynamic_link.dem.gateway.sce
scilab/modules/genetic_algorithms/demos/genetic_algorithms.dem.gateway.sce
scilab/modules/graphics/demos/2d_3d_plots/2d_3d_plots.dem.gateway.sce
scilab/modules/graphics/demos/2d_3d_plots/abaque.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/champ.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/contour.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/contour_3d_2.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/contour_3d_3.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/contour_3d_4.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/contourf.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/contourf2.dem.sce [new file with mode: 0644]
scilab/modules/graphics/demos/2d_3d_plots/errbar.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/fac3d.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/fac3d1.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/fchamp.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/fcontour.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/fgrayplot.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/fplot2d.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/fplot3d.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/fplot3d1.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/grayplot.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/histplot.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/param3d_1.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/param3d_2.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/plot2d.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/plot2d1_1.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/plot2d1_2.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/plot2d3.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/plot3d.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/plot3d1.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/plotyy.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/plotyyy.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/subplot.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/xgeom.dem.sce
scilab/modules/graphics/demos/2d_3d_plots/zgrid.dem.sce
scilab/modules/graphics/demos/anim/anim.dem.gateway.sce
scilab/modules/graphics/demos/anim/anim1/anim1.sce
scilab/modules/graphics/demos/anim/anim1/anim1_gateway.sce
scilab/modules/graphics/demos/anim/anim2/anim2.sce
scilab/modules/graphics/demos/anim/anim2/anim2_gateway.sce
scilab/modules/graphics/demos/anim/anim3/anim3.sce
scilab/modules/graphics/demos/anim/anim3/anim3_gateway.sce
scilab/modules/graphics/demos/anim/anim4/anim4.sce
scilab/modules/graphics/demos/anim/anim4/anim4_gateway.sce
scilab/modules/graphics/demos/anim/anim5/anim5.sce
scilab/modules/graphics/demos/anim/anim5/anim5_gateway.sce
scilab/modules/graphics/demos/anim/anim6/anim6.sce
scilab/modules/graphics/demos/anim/anim6/anim6.sci [deleted file]
scilab/modules/graphics/demos/anim/anim7/anim7.sce
scilab/modules/graphics/demos/anim/anim7/anim7_gateway.sce
scilab/modules/graphics/demos/anim/anim8/anim8.sci
scilab/modules/graphics/demos/anim/anim8/anim8_gateway.sce
scilab/modules/graphics/demos/bar/bar.dem.sce
scilab/modules/graphics/demos/basic_functions/basic_functions.dem.gateway.sce
scilab/modules/graphics/demos/basic_functions/basic_functions_1.dem.sce
scilab/modules/graphics/demos/basic_functions/basic_functions_2.dem.sce
scilab/modules/graphics/demos/basic_functions/basic_functions_3.dem.sce
scilab/modules/graphics/demos/basic_functions/basic_functions_4.dem.sce
scilab/modules/graphics/demos/basic_functions/basic_functions_5.dem.sce
scilab/modules/graphics/demos/basic_functions/basic_functions_6.dem.sce
scilab/modules/graphics/demos/basic_functions/basic_functions_7.dem.sce
scilab/modules/graphics/demos/basic_functions/basic_functions_8.dem.sce
scilab/modules/graphics/demos/bezier/bezier.dem.gateway.sce
scilab/modules/graphics/demos/bezier/bezier3dtest.sce
scilab/modules/graphics/demos/bezier/beziersurftest.sce
scilab/modules/graphics/demos/bezier/beziertest.sce
scilab/modules/graphics/demos/bezier/c1test.sce
scilab/modules/graphics/demos/bezier/gammatest.sce
scilab/modules/graphics/demos/bike.dem [deleted file]
scilab/modules/graphics/demos/cmplxfunc/MacCmplx.sci
scilab/modules/graphics/demos/cmplxfunc/cmplxfunc.dem.gateway.sce
scilab/modules/graphics/demos/cmplxfunc/cmplxfunc.sce [deleted file]
scilab/modules/graphics/demos/cmplxfunc/cmplxfunc.sci [deleted file]
scilab/modules/graphics/demos/cmplxfunc/cmplxfunc_dial.sce [deleted file]
scilab/modules/graphics/demos/cmplxfunc/demo_acos.dem.sce
scilab/modules/graphics/demos/cmplxfunc/demo_acosh.dem.sce
scilab/modules/graphics/demos/cmplxfunc/demo_asin.dem.sce
scilab/modules/graphics/demos/cmplxfunc/demo_asinh.dem.sce
scilab/modules/graphics/demos/cmplxfunc/demo_atan.dem.sce
scilab/modules/graphics/demos/cmplxfunc/demo_atanh.dem.sce
scilab/modules/graphics/demos/cmplxfunc/demo_cos.dem.sce
scilab/modules/graphics/demos/cmplxfunc/demo_cosh.dem.sce
scilab/modules/graphics/demos/cmplxfunc/demo_custom.dem.sce
scilab/modules/graphics/demos/cmplxfunc/demo_exp.dem.sce
scilab/modules/graphics/demos/cmplxfunc/demo_log.dem.sce
scilab/modules/graphics/demos/cmplxfunc/demo_sin.dem.sce
scilab/modules/graphics/demos/cmplxfunc/demo_sinh.dem.sce
scilab/modules/graphics/demos/cmplxfunc/demo_tan.dem.sce
scilab/modules/graphics/demos/cmplxfunc/demo_tanh.dem.sce
scilab/modules/graphics/demos/colormap.dem.sce [deleted file]
scilab/modules/graphics/demos/colormap/colormap.dem.sce [moved from scilab/modules/graphics/demos/colormap.dem.sci with 98% similarity]
scilab/modules/graphics/demos/contourf.dem [deleted file]
scilab/modules/graphics/demos/fec/fec.dem.gateway.sce
scilab/modules/graphics/demos/fec/fec.ex1 [deleted file]
scilab/modules/graphics/demos/fec/fec.ex2 [deleted file]
scilab/modules/graphics/demos/fec/fec.ex2.dem.sce
scilab/modules/graphics/demos/fec/fec.ex3 [deleted file]
scilab/modules/graphics/demos/fec/fec.ex3.dem.sce
scilab/modules/graphics/demos/fec/fec.ex4 [deleted file]
scilab/modules/graphics/demos/fec/fec.ex4.dem.sce
scilab/modules/graphics/demos/fec/fec.info
scilab/modules/graphics/demos/fec/fec_demo.sci
scilab/modules/graphics/demos/graphics.dem.gateway.sce
scilab/modules/graphics/demos/misc.dem.sci [deleted file]
scilab/modules/graphics/demos/misc/misc.dem [deleted file]
scilab/modules/graphics/demos/misc/misc.dem.sce
scilab/modules/graphics/demos/misc/misc.dem.sci [deleted file]
scilab/modules/graphics/demos/misc/numerique.dem [deleted file]
scilab/modules/graphics/demos/misc/oscil.dem [deleted file]
scilab/modules/graphics/demos/misc/oscil.sci [deleted file]
scilab/modules/graphics/demos/misc/point.dem [deleted file]
scilab/modules/graphics/demos/misc_new/misc.dem.gateway.sce [deleted file]
scilab/modules/graphics/demos/misc_new/misc.sce [deleted file]
scilab/modules/graphics/demos/misc_new/numerique.dem [deleted file]
scilab/modules/graphics/demos/misc_new/oscil.dem [deleted file]
scilab/modules/graphics/demos/misc_new/oscil.sci [deleted file]
scilab/modules/graphics/demos/misc_new/point.dem [deleted file]
scilab/modules/graphics/demos/peaks.sci [deleted file]
scilab/modules/graphics/demos/portrait.dem [deleted file]
scilab/modules/graphics/demos/sd.sav [deleted file]
scilab/modules/graphics/demos/surface/Macros.sci
scilab/modules/graphics/demos/surface/bh.sce
scilab/modules/graphics/demos/surface/cplxroot.sce
scilab/modules/graphics/demos/surface/hole3d.sce
scilab/modules/graphics/demos/surface/hole3d1.sce
scilab/modules/graphics/demos/surface/moebius.sce
scilab/modules/graphics/demos/surface/rings.sce
scilab/modules/graphics/demos/surface/shell.sce
scilab/modules/graphics/demos/surface/sphere.sce
scilab/modules/graphics/demos/surface/spiral.sce
scilab/modules/graphics/demos/surface/surfaces.dem [deleted file]
scilab/modules/graphics/demos/surface/surfaces.dem.gateway.sce
scilab/modules/graphics/demos/surface/surfaces.sci [deleted file]
scilab/modules/graphics/demos/surface/torus.sce
scilab/modules/graphics/demos/surface/torus1.sce
scilab/modules/graphics/demos/surface/tube.sce
scilab/modules/graphics/demos/textrendering/latex/coloredlabel.dem.sce
scilab/modules/graphics/demos/textrendering/latex/fulltest.dem.sce
scilab/modules/graphics/demos/textrendering/latex/latexsubplot.dem.sce
scilab/modules/graphics/demos/textrendering/latex/simple.dem.sce
scilab/modules/graphics/demos/textrendering/textrendering.dem.gateway.sce
scilab/modules/graphics/demos/xsetechfig.sce [deleted file]
scilab/modules/graphics/macros/%_fec.sci
scilab/modules/gui/demos/gui.dem.gateway.sce
scilab/modules/optimization/demos/datafit/datafit.dem.gateway.sce
scilab/modules/optimization/demos/icse/icse.dem.gateway.sce
scilab/modules/optimization/demos/neldermead/neldermead.dem.gateway.sce
scilab/modules/optimization/demos/optim/optim.dem.gateway.sce
scilab/modules/optimization/demos/optimization.dem.gateway.sce
scilab/modules/polynomials/demos/polynomials.dem.gateway.sce
scilab/modules/randlib/demos/random.dem.gateway.sce
scilab/modules/scicos/demos/control_systems.dem.gateway.sce
scilab/modules/scicos/demos/electrical_systems.dem.gateway.sce
scilab/modules/scicos/demos/live.dem.gateway.sce
scilab/modules/scicos/demos/mechanical_systems.dem.gateway.sce
scilab/modules/scicos/demos/modelica_demos.dem.gateway.sce
scilab/modules/scicos/demos/old_demos.dem.gateway.sce
scilab/modules/scicos/demos/scicos.dem.gateway.sce
scilab/modules/scicos/demos/standard.dem.gateway.sce
scilab/modules/signal_processing/demos/signal.dem.gateway.sce
scilab/modules/simulated_annealing/demos/simulated_annealing.dem.gateway.sce
scilab/modules/tclsci/demos/tk/tcltk.dem.gateway.sce
scilab/modules/xcos/demos/control_systems.dem.gateway.sce
scilab/modules/xcos/demos/electrical_systems.dem.gateway.sce
scilab/modules/xcos/demos/mechanical_systems.dem.gateway.sce
scilab/modules/xcos/demos/modelica_demos.dem.gateway.sce
scilab/modules/xcos/demos/old_demos.dem.gateway.sce
scilab/modules/xcos/demos/scicos.dem.gateway.sce
scilab/modules/xcos/demos/standard.dem.gateway.sce
scilab/modules/xcos/demos/xcos.dem.gateway.sce

index 86b9c73..e6476b7 100644 (file)
@@ -1,10 +1,19 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2008 - INRIA - Allan CORNET
+// Copyright (C) 2010 - DIGITEO - Allan CORNET
 //
 // This file is released into the public domain
 
-mode(-1);
-lines(0);
 
-disp("c_sum(3,4)");
-disp(c_sum(3,4));
+function demo_c_sum()
+
+  mode(-1);
+  lines(0);
+
+  disp("c_sum(3,4)");
+  disp(c_sum(3,4));
+  
+endfunction
+
+demo_c_sum();
+clear demo_c_sum;
index 4ba0965..0093d67 100644 (file)
@@ -1,12 +1,21 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2008 - INRIA - Allan CORNET
+// Copyright (C) 2010 - DIGITEO - Allan CORNET
 //
 // This file is released into the public domain
 
-mode(-1);
-lines(0);
 
-disp("cpp_find(''Scilab is a numerical computational package'',''numerical'')");
-disp('position : ' + string(cpp_find('Scilab is a numerical computational package','numerical')));
-disp("cpp_find(''Scilab is a numerical computational package'',''package'')");
-disp('position: ' + string(cpp_find('Scilab is a numerical computational package','package')));
+function demo_cpp_find()
+  mode(-1);
+  lines(0);
+
+  disp("cpp_find(''Scilab is a numerical computational package'',''numerical'')");
+  disp('position : ' + string(cpp_find('Scilab is a numerical computational package','numerical')));
+  disp("cpp_find(''Scilab is a numerical computational package'',''package'')");
+  disp('position: ' + string(cpp_find('Scilab is a numerical computational package','package')));
+  
+endfunction
+
+
+demo_cpp_find();
+clear demo_cpp_find;
\ No newline at end of file
index f5889f1..34465da 100644 (file)
@@ -1,10 +1,19 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2008 - INRIA - Allan CORNET
+// Copyright (C) 2010 - DIGITEO - Allan CORNET
 //
 // This file is released into the public domain
 
-mode(-1);
-lines(0);
+function demo_fortran_sum()
+
+  mode(-1);
+  lines(0);
+
+  disp("fortran_sum(3,4)");
+  disp(fortran_sum(3,4));
+  
+endfunction
+
+demo_fortran_sum();
+clear demo_fortran_sum;
 
-disp("fortran_sum(3,4)");
-disp(fortran_sum(3,4));
index c92615b..7ee65f4 100644 (file)
@@ -1,10 +1,19 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2008 - INRIA - Allan CORNET
+// Copyright (C) 2010 - DIGITEO - Allan CORNET
 //
 // This file is released into the public domain
 
-mode(-1);
-lines(0);
+function demo_scilab_sum()
 
-disp("scilab_sum(3,4)");
-disp(scilab_sum(3,4));
+  mode(-1);
+  lines(0);
+
+  disp("scilab_sum(3,4)");
+  disp(scilab_sum(3,4));
+
+endfunction
+
+
+demo_scilab_sum();
+clear demo_scilab_sum;
\ No newline at end of file
index f5d1697..d69832b 100644 (file)
@@ -15,3 +15,4 @@ subdemolist = ["LQG"                , "lqg/lqg.dem"
                "Robust control"     , "robust/rob.dem"]
 
 subdemolist(:,2) = demopath + subdemolist(:,2);
+clear demopath;
\ No newline at end of file
index 9cb3910..9eb4737 100644 (file)
@@ -5,18 +5,24 @@
 // This file is distributed under the same license as the Scilab package.
 //
 
-deff('[]=demoexc(fil)','exec(''SCI/modules/cacsd/demos/''+fil)')
-while %t do
-  n=x_choose(['LQG','Mixed-sensitivity','PID'],'Select a demo');
-  select n
-  case 0
-    break
-  case 1
-    demoexc('lqg/lqg.dem')
-  case 2
-    demoexc('mixed.dem')
-  case 3
-    demoexc('pid.dem')
+function demo_cont()
+
+  deff('[]=demoexc(fil)','exec(''SCI/modules/cacsd/demos/''+fil)')
+  while %t do
+    n=x_choose(['LQG','Mixed-sensitivity','PID'],'Select a demo');
+    select n
+    case 0
+      break
+    case 1
+      demoexc('lqg/lqg.dem')
+    case 2
+      demoexc('mixed.dem')
+    case 3
+      demoexc('pid.dem')
+    end
   end
-end
+  
+endfunction
 
+demo_cont();
+clear demo_cont;
index bd56645..54966d6 100644 (file)
@@ -3,16 +3,19 @@
 //
 // This file is released into the public domain
 
-// Clear the functions defined in car.sci to avoid warnings
-clear car_solve polyline car_polynomial_curve display_car_trajectory build_car draw_car polyline
+function demo_car()
 
-exec(get_absolute_file_path("car.dem.sce") + "/car.sci",-1);
+  exec("SCI/modules/cacsd/demos/flat/car.sci",-1);
 
-initial               =[3;3;0;0];
-final                 =[0;0;0;0];
-my_handle             = scf(100001);
-clf(my_handle,"reset");
-my_handle.pixmap      = "off" ;
-toolbar(my_handle.figure_id,"off");
-state=car_solve(initial,final);
-display_car_trajectory(state);
+  initial               =[3;3;0;0];
+  final                 =[0;0;0;0];
+  my_handle             = scf(100001);
+  clf(my_handle,"reset");
+  my_handle.pixmap      = "off" ;
+  toolbar(my_handle.figure_id,"off");
+  state=car_solve(initial,final);
+  display_car_trajectory(state);
+endfunction
+
+demo_car();
+clear demo_car;
\ No newline at end of file
index 5de17b6..8d5cebd 100644 (file)
@@ -134,27 +134,29 @@ function C=build_car()
 endfunction
 
 function draw_car(C,pos)
-  drawlater()
-  [x,y,theta,phi]=(pos(1),pos(2),pos(3),pos(4))
-  bigL=1
-  Rc=[cos(theta) sin(theta);-sin(theta) cos(theta)]
-  // the car
-  xy = [-2,-2;7,-2;8,-1;8,1;7,2;-2,2;-2,-2]/6
-  C(1).data=ones(xy)*diag([x;y])+bigL*xy*Rc
-  // rear wheels
-  xy=[[-1 1]/8; [1 1]/6]'
-  C(2).data=ones(xy)*diag([x;y])+bigL*xy*Rc
-  xy=[[-1 1]/8; -[1 1]/6]'
-  C(3).data=ones(xy)*diag([x;y])+bigL*xy*Rc
-  // front wheels
-  xy=[(1-cos(phi)/8) (1/6-sin(phi)/8)
+  if is_handle_valid(C) then
+    drawlater()
+    [x,y,theta,phi]=(pos(1),pos(2),pos(3),pos(4))
+    bigL=1
+    Rc=[cos(theta) sin(theta);-sin(theta) cos(theta)]
+    // the car
+    xy = [-2,-2;7,-2;8,-1;8,1;7,2;-2,2;-2,-2]/6
+    C(1).data=ones(xy)*diag([x;y])+bigL*xy*Rc
+    // rear wheels
+    xy=[[-1 1]/8; [1 1]/6]'
+    C(2).data=ones(xy)*diag([x;y])+bigL*xy*Rc
+    xy=[[-1 1]/8; -[1 1]/6]'
+    C(3).data=ones(xy)*diag([x;y])+bigL*xy*Rc
+    // front wheels
+    xy=[(1-cos(phi)/8) (1/6-sin(phi)/8)
       (1+cos(phi)/8) (1/6+sin(phi)/8)]
-  C(4).data=ones(xy)*diag([x;y])+bigL*xy*Rc
-  xy=[(1-cos(phi)/8) (-1/6-sin(phi)/8)
+    C(4).data=ones(xy)*diag([x;y])+bigL*xy*Rc
+    xy=[(1-cos(phi)/8) (-1/6-sin(phi)/8)
       (1+cos(phi)/8) (-1/6+sin(phi)/8)]
-  C(5).data=ones(xy)*diag([x;y])+bigL*xy*Rc
-  drawnow()
-  show_pixmap();
+    C(5).data=ones(xy)*diag([x;y])+bigL*xy*Rc
+    drawnow()
+    show_pixmap();
+  end
 endfunction
 
 function h=polyline(xy)
diff --git a/scilab/modules/cacsd/demos/flat/demo_car_eng.htm b/scilab/modules/cacsd/demos/flat/demo_car_eng.htm
deleted file mode 100644 (file)
index d331dcd..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<html>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
-<title>demo_car</title>
-</head>
-<body bgcolor="#FFFFFF">
-<center><h1><font color="blue">Car parking</font></h1></center>
-
-
-<h2>
-
-<center>
-<p>Non linear system control</p>
-<p>Flat systems with Frenet formulas </p>
-<p></p>
-<p></p>
-
-
-<p>par </p>
-<p></p>
-<p></p>
-
-<p>Pierre ROUCHON</p>
-<p>Centre Automatique et Systèmes,</p>
-<p>Ecole des Mines de Paris</p>
-</center>
-</h2>
-
-</body>
-</html>
diff --git a/scilab/modules/cacsd/demos/flat/demo_car_fr.htm b/scilab/modules/cacsd/demos/flat/demo_car_fr.htm
deleted file mode 100644 (file)
index 37f69fc..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<html>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
-<title>demo_car</title>
-</head>
-<body bgcolor="#FFFFFF">
-<center><h1><font color="blue">Stationnement d'une voiture</font></h1></center>
-
-
-<h2>
-
-<center>
-<p>Contrôle des systèmes non linéaires</p>
-<p>Méthode des systèmes plats et formules de Frenet</p>
-<p></p>
-<p></p>
-
-
-<p>par </p>
-<p></p>
-<p></p>
-
-<p>Pierre ROUCHON</p>
-<p>Centre Automatique et Systemes,</p>
-<p>Ecole des Mines de Paris</p>
-</center>
-</h2>
-
-</body>
-</html>
diff --git a/scilab/modules/cacsd/demos/flat/demo_truck_eng_htm b/scilab/modules/cacsd/demos/flat/demo_truck_eng_htm
deleted file mode 100644 (file)
index d416c8e..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<html>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
-<title>demo_truck</title>
-</head>
-<body bgcolor="#FFFFFF">
-<center><h1><font color="blue">Truck parking</font></h1></center>
-
-
-<h2>
-
-<center>
-<p>Non linear system control</p>
-<p>Flat systems with Frenet formulas </p>
-<p></p>
-<p></p>
-
-
-<p>par </p>
-<p></p>
-<p></p>
-
-<p>Pierre ROUCHON</p>
-<p>Centre Automatique et Systèmes,</p>
-<p>Ecole des Mines de Paris</p>
-</center>
-</h2>
-
-</body>
-</html>
diff --git a/scilab/modules/cacsd/demos/flat/demo_truck_fr.htm b/scilab/modules/cacsd/demos/flat/demo_truck_fr.htm
deleted file mode 100644 (file)
index 2a52096..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<html>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
-<title>demo_truck</title>
-</head>
-<body bgcolor="#FFFFFF">
-<center><h1><font color="blue">Stationnement d'un semi remorque</font></h1></center>
-
-
-<h2>
-
-<center>
-<p>Contrôle des systèmes non linéaires</p>
-<p>Méthode des systèmes plats et formules de Frenet</p>
-<p></p>
-<p></p>
-
-
-<p>par </p>
-<p></p>
-<p></p>
-
-<p>Pierre ROUCHON</p>
-<p>Centre Automatique et Systemes,</p>
-<p>Ecole des Mines de Paris</p>
-</center>
-</h2>
-
-</body>
-</html>
index df1388e..9216569 100644 (file)
@@ -9,3 +9,4 @@ subdemolist = ["Car"                ,"car.dem.sce"   ; ..
                "Two trailers truck" ,"truck.dem.sce" ]
 
 subdemolist(:,2) = demopath + subdemolist(:,2);
+clear demopath;
\ No newline at end of file
index 9d44739..915a63a 100644 (file)
@@ -5,15 +5,20 @@
 
 // Clear the functions defined in truck.sci to avoid warnings
 
-clear truck_solve polyline truck_polynomial_curve cr2Tfjt cr2Tkf cr2Tfk display_truck_trajectory build_truck draw_truck polyline
 
-exec(get_absolute_file_path("truck.dem.sce") + "/truck.sci",-1);
+function demo_truck()
+  exec("SCI/modules/cacsd/demos/flat/truck.sci",-1);
 
-initial   = [-2;3;0.5235988;0;0;1];
-final     = [0;0;0;0;0;0];
-state     = truck_solve(initial,final);
-my_handle = scf(100001);
-clf(my_handle,"reset");
-my_handle.pixmap = "off" ;
-toolbar(my_handle.figure_id,"off") ;
-display_truck_trajectory(state);
+  initial   = [-2;3;0.5235988;0;0;1];
+  final     = [0;0;0;0;0;0];
+  state     = truck_solve(initial,final);
+  my_handle = scf(100001);
+  clf(my_handle,"reset");
+  my_handle.pixmap = "off" ;
+  toolbar(my_handle.figure_id,"off") ;
+  display_truck_trajectory(state);
+  
+endfunction
+
+demo_truck();
+clear demo_truck;
\ No newline at end of file
index 890d019..12abeb5 100644 (file)
@@ -208,7 +208,9 @@ function display_truck_trajectory(state)
   rect=matrix(a.data_bounds',-1,1)
   xpoly(rect([1 3 3 1]),rect([2,2,4,4]),'lines',1)
   C=build_truck()
-  Cinit=[];Cend=[];Cinter=[];
+  Cinit=[];
+  Cend=[];
+  Cinter=[];
   for k=1:size(C,'*')
     Cinit=[Cinit copy(C(k))];
     Cinter=[Cinter,copy(C(k))];
index c8b21db..78e5a3f 100644 (file)
 // This file is distributed under the same license as the Scilab package.
 //
 
-mode(-1);
-oldln=lines();lines(0)
-//display the diagram
-x=[5,10,20,40,50,70,80,90];xmin=-10;xmax=100;
-y=[22,28,30,32];ymin=12;ymax=40;
-
-xx=[x([1 2 2 7 4 6 3 4 5 6 3 3 5 5]);x([3,2,7,7,5,8,3,4,5,6,4,4,6,6])];
-yy=[y([3,1,1,1,3,3,2,2,2,2,2,4,2,4]);y([3,3,1,3,3,3,4,4,4,4,2,4,2,4])];
-
-scf(0);clf();show_window();
-a=gca();a.data_bounds=[xmin ymin;xmax ymax];a.box='on';
-xpolys(xx,yy)
-xstring(28,30,'K');xstring(56,30,'Plant');xstring(12,28.80,'-');
-xtitle('PLANT   and   CONTROLLER')
-
-
-// xset("window",0);clf();show_window();
-// plot2d(xx,yy,ones(1,16),'022');
-// xstring(28,30,'K');xstring(56,30,'Plant');xstring(12,28.80,'-');
-// xtitle('PLANT   and   CONTROLLER')
-
-path=get_absolute_file_path('lqg.dem');
-s=poly(0,'s');z=poly(0,'z');
-messagebox(['Simple example of SISO LQG Design';
+function demo_lqg()
+
+  mode(-1);
+  oldln=lines();
+  lines(0);
+  //display the diagram
+  x=[5,10,20,40,50,70,80,90];xmin=-10;xmax=100;
+  y=[22,28,30,32];ymin=12;ymax=40;
+
+  xx=[x([1 2 2 7 4 6 3 4 5 6 3 3 5 5]);x([3,2,7,7,5,8,3,4,5,6,4,4,6,6])];
+  yy=[y([3,1,1,1,3,3,2,2,2,2,2,4,2,4]);y([3,3,1,3,3,3,4,4,4,4,2,4,2,4])];
+
+  scf(0);
+  clf();
+  show_window();
+  a=gca();
+  a.data_bounds=[xmin ymin;xmax ymax];
+  a.box='on';
+  xpolys(xx,yy)
+  xstring(28,30,'K');
+  xstring(56,30,'Plant');
+  xstring(12,28.80,'-');
+  xtitle('PLANT   and   CONTROLLER')
+
+
+  path=get_absolute_file_path('lqg.dem');
+  s=poly(0,'s');z=poly(0,'z');
+  messagebox(['Simple example of SISO LQG Design';
            'Demo is in file '+path+'lqg.dem';
            'Computes the LQG compensator and plots response'],"modal");
 
-n=x_choose(['Continuous time';'Discrete time'],'Select time domain');
-
-select n
-case 0
-  return
-case 1
-  mode(1)
-  s=poly(0,'s');
-  str='(s-1)/(s^2-5*s+1)';
-  rep=x_dialog('Nominal plant?',str)
-  if rep==[] then return,end
-  Plant=evstr(rep);
-  Plant=syslin('c',Plant);
-  mode(-1)
-case 2
-  mode(1)
-  z=poly(0,'z');
-  str='(z+1)/(z^2-5*z+2)'
-  rep=x_dialog('Nominal plant?',str)
-  if rep==[] then return,end
-  Plant=evstr(rep);
-  Plant=syslin('d',Plant);
-  mode(-1)
-end
-
-mode(1)
-
-//Nominal Plant
-
-P22=tf2ss(Plant);    //...in state-space form
-[ny,nu,nx]=size(P22);
-messagebox('Now enter weighting matrices',"modal");
-rep=x_matrix('x-weighting matrix',eye(nx,nx))
-if rep==[] then return,end
-Qx=evstr(rep);
-rep=x_matrix('u-weighting matrix',eye(nu,nu));
-if rep==[] then return,end
-Qu=evstr(rep);
-bigQ=sysdiag(Qx,Qu);
-rep=x_matrix('x-noise covariance matrix',eye(nx,nx))
-if rep==[] then return,end
-Rx=evstr(rep);
-rep=x_matrix('y-noise covariance matrix',eye(ny,ny))
-if rep==[] then return,end
-Ry=evstr(rep);
-bigR=sysdiag(Rx,Ry);
-[Plqg,r]=lqg2stan(P22,bigQ,bigR);     //LQG pb as a standard problem
-Klqg=lqg(Plqg,r);                     //LQG compensator
-
-disp(spec(h_cl(Plqg,r,Klqg)),'closed loop eigenvalues:');    //Check internal stability
-[Slqg,Rlqg,Tlqg]=sensi(P22,Klqg);  //Sensitivity functions
-
-disp(clean(ss2tf(Slqg)),'Sensitivity function');
-disp(clean(ss2tf(Tlqg)),'Complementary sensitivity function');
-
-mode(-1);
-
-messagebox('Closed-loop response',"modal");
+  n=x_choose(['Continuous time';'Discrete time'],'Select time domain');
 
-resp=['Frequency response';'Time response'];
-while %t do
-  n=x_choose(resp,'Select response(s)');
   select n
   case 0
-    disp("LQG demo stops!");break;
-  case 1 then
+    return
+  case 1
     mode(1)
-    scf(0);clf();show_window();bode(Tlqg);
+    s=poly(0,'s');
+    str='(s-1)/(s^2-5*s+1)';
+    rep=x_dialog('Nominal plant?',str)
+    if rep==[] then return,end
+    Plant=evstr(rep);
+    Plant=syslin('c',Plant);
     mode(-1)
   case 2
-    if Plant(4)=='c' then
-      mode(1)
-      defv=['0.1';'20'];
-      _title='Enter Sampling period and Tmax';
-      rep=x_mdialog(_title,['Sampling period?';'Tmax?'],defv)
-      if rep==[] then break,end
-      dttmax=evstr(rep)
-      dt=evstr(dttmax(1));tmax=evstr(dttmax(2));
-      t=0:dt/5:tmax;
-      n1=x_choose(['Step response?';'Impulse response?'],'Simulation:');
-      select n1
-      case 1 then
-        scf(1);clf();show_window();
-        plot2d([t',t'],[(csim('step',t,Tlqg))',ones(t')]);
-      case 2 then
-        scf(1);clf();show_window();
-        plot2d([t',t'],[(csim('impul',t,Tlqg))',0*t']);
-      end
-      mode(-1)
-    elseif Plant(4)=='d' then
+    mode(1)
+    z=poly(0,'z');
+    str='(z+1)/(z^2-5*z+2)'
+    rep=x_dialog('Nominal plant?',str)
+    if rep==[] then return,end
+    Plant=evstr(rep);
+    Plant=syslin('d',Plant);
+    mode(-1)
+  end
+  
+  mode(1)
+
+  //Nominal Plant
+
+  P22=tf2ss(Plant);    //...in state-space form
+  [ny,nu,nx]=size(P22);
+  messagebox('Now enter weighting matrices',"modal");
+  rep=x_matrix('x-weighting matrix',eye(nx,nx))
+  if rep==[] then return,end
+  Qx=evstr(rep);
+  rep=x_matrix('u-weighting matrix',eye(nu,nu));
+  if rep==[] then return,end
+  Qu=evstr(rep);
+  bigQ=sysdiag(Qx,Qu);
+  rep=x_matrix('x-noise covariance matrix',eye(nx,nx))
+  if rep==[] then return,end
+  Rx=evstr(rep);
+  rep=x_matrix('y-noise covariance matrix',eye(ny,ny))
+  if rep==[] then return,end
+  Ry=evstr(rep);
+  bigR=sysdiag(Rx,Ry);
+  [Plqg,r]=lqg2stan(P22,bigQ,bigR);     //LQG pb as a standard problem
+  Klqg=lqg(Plqg,r);                     //LQG compensator
+  
+  disp(spec(h_cl(Plqg,r,Klqg)),'closed loop eigenvalues:');    //Check internal stability
+  [Slqg,Rlqg,Tlqg]=sensi(P22,Klqg);  //Sensitivity functions
+
+  disp(clean(ss2tf(Slqg)),'Sensitivity function');
+  disp(clean(ss2tf(Tlqg)),'Complementary sensitivity function');
+  
+  mode(-1);
+
+  messagebox('Closed-loop response',"modal");
+
+  resp=['Frequency response';'Time response'];
+  while %t do
+    n=x_choose(resp,'Select response(s)');
+    select n
+    case 0
+      disp("LQG demo stops!");break;
+    case 1 then
       mode(1)
-      defv=['30'];
-      _title='Tmax?';
-      rep=x_mdialog(_title,['Tmax='],defv)
-      if rep==[] then break,end
-      Tmax=evstr(rep);
+      scf(0);
+      clf();
+      show_window();
+      bode(Tlqg);
       mode(-1)
-      n2=x_choose(['Step response?';'Impulse response?'],'Simulation:');
-      select n2
-      case 0 then
-        break;
-      case 1 then
+    case 2
+      if Plant(4)=='c' then
         mode(1)
-        u=ones(1,Tmax);u(1)=0;
-        scf(1);clf();show_window();
-        plot2d([(1:Tmax)',(1:Tmax)'],[(dsimul(Tlqg,u))',(ones(1:Tmax)')])
+        defv=['0.1';'20'];
+        _title='Enter Sampling period and Tmax';
+        rep=x_mdialog(_title,['Sampling period?';'Tmax?'],defv)
+        if rep==[] then break,end
+        dttmax=evstr(rep)
+        dt=evstr(dttmax(1));
+        tmax=evstr(dttmax(2));
+        t=0:dt/5:tmax;
+        n1=x_choose(['Step response?';'Impulse response?'],'Simulation:');
+        select n1
+        case 1 then
+          scf(1);
+          clf();
+          show_window();
+          plot2d([t',t'],[(csim('step',t,Tlqg))',ones(t')]);
+        case 2 then
+          scf(1);
+          clf();
+          show_window();
+          plot2d([t',t'],[(csim('impul',t,Tlqg))',0*t']);
+        end
         mode(-1)
-      case 2 then
+      elseif Plant(4)=='d' then
         mode(1)
-        u=zeros(1,Tmax);u(1)=1;
-        scf(1);clf();show_window();
-        plot2d((1:Tmax)',(dsimul(Tlqg,u))')
+        defv=['30'];
+        _title='Tmax?';
+        rep=x_mdialog(_title,['Tmax='],defv)
+        if rep==[] then break,end
+        Tmax=evstr(rep);
         mode(-1)
+        n2=x_choose(['Step response?';'Impulse response?'],'Simulation:');
+        select n2
+        case 0 then
+        break;
+        case 1 then
+          mode(1)
+          u=ones(1,Tmax);u(1)=0;
+          scf(1);clf();show_window();
+          plot2d([(1:Tmax)',(1:Tmax)'],[(dsimul(Tlqg,u))',(ones(1:Tmax)')])
+          mode(-1)
+        case 2 then
+          mode(1)
+          u=zeros(1,Tmax);u(1)=1;
+          scf(1);clf();show_window();
+          plot2d((1:Tmax)',(dsimul(Tlqg,u))')
+          mode(-1)
+        end
       end
     end
   end
-end
-lines(oldln(2))
-clear s z n str rep Plant P22 ny nu nx Qx Qu bigQ Rx Ry bigR  Plqg r 
-clear Klqg Slqg Rlqg Tlqg resp _title dttmax dt t n1 defv Tmax n2 u oldln
+  lines(oldln(2))
+endfunction
+
+demo_lqg()
+clear demo_lqg;
index 2694930..f7988c1 100644 (file)
@@ -5,33 +5,40 @@
 // This file is distributed under the same license as the Scilab package.
 //
 
-s=poly(0,'s');
-Plant=[1/(s+1),s/(s-1)^2;(s-1)*s/(s^2-3*s+2),2/s];
-Plant=syslin('c',[1/(s+1)*s/(s-1)^2]);     //Nominal Plant
-P22=tf2ss(Plant);    //...in state-space form
-[ny,nu,nx]=size(P22);
-rand('seed',0);rand('normal');
-bigQ=rand(nx+nu,nx+nu);bigQ=bigQ*bigQ';
-bigR=rand(nx+ny,nx+ny);bigR=bigR*bigR';  //random weighting matrices
-[Plqg,r]=lqg2stan(P22,bigQ,bigR);     //LQG pb as a standard problem
-Klqg=lqg(Plqg,r);          //Controller
-spec(h_cl(Plqg,r,Klqg))    //Check internal stability
-[Slqg,Rlqg,Tlqg]=sensi(P22,Klqg);  //Sensitivity functions
-frq=logspace(-3,3);     //10^-3  to 10^3 
-y=svplot(Slqg);       //Computes singular values;
-clf();xset("window",0);gainplot(frq,y)   //Plot sing. values
-w1=1/(s+1);
-w2=100;
-[Ptmp,r]=augment(P22,'SR');         //"S/KS" problem
-Pinf=sysdiag(w1,w2,1)*Ptmp;        //Weighting functions
-[Kinf,ro]=h_inf(Pinf,r,0,0.1,50);
-[Sinf,Rinf,Tinf]=sensi(P22,Kinf);  //Sensitivity functions
-y=svplot(Sinf);       //Computes singular values;
-xset("window",1);show_window();gainplot(frq,y)   //Plot sing. values
+function demo_lqg2()
 
-clf();t=0:0.01:30;u=sin(t);
-plot2d([t',t'],[u',(flts(u,dscr(Tlqg,0.1))')])
+  s=poly(0,'s');
+  Plant=[1/(s+1),s/(s-1)^2;(s-1)*s/(s^2-3*s+2),2/s];
+  Plant=syslin('c',[1/(s+1)*s/(s-1)^2]);     //Nominal Plant
+  P22=tf2ss(Plant);    //...in state-space form
+  [ny,nu,nx]=size(P22);
+  rand('seed',0);rand('normal');
+  bigQ=rand(nx+nu,nx+nu);bigQ=bigQ*bigQ';
+  bigR=rand(nx+ny,nx+ny);bigR=bigR*bigR';  //random weighting matrices
+  [Plqg,r]=lqg2stan(P22,bigQ,bigR);     //LQG pb as a standard problem
+  Klqg=lqg(Plqg,r);          //Controller
+  spec(h_cl(Plqg,r,Klqg))    //Check internal stability
+  [Slqg,Rlqg,Tlqg]=sensi(P22,Klqg);  //Sensitivity functions
+  frq=logspace(-3,3);     //10^-3  to 10^3 
+  y=svplot(Slqg);       //Computes singular values;
+  clf();
+  xset("window",0);
+  gainplot(frq,y)   //Plot sing. values
+  w1=1/(s+1);
+  w2=100;
+  [Ptmp,r]=augment(P22,'SR');         //"S/KS" problem
+  Pinf=sysdiag(w1,w2,1)*Ptmp;        //Weighting functions
+  [Kinf,ro]=h_inf(Pinf,r,0,0.1,50);
+  [Sinf,Rinf,Tinf]=sensi(P22,Kinf);  //Sensitivity functions
+  y=svplot(Sinf);       //Computes singular values;
+  xset("window",1);
+  show_window();
+  gainplot(frq,y)   //Plot sing. values
 
-clear s  n  Plant P22 ny nu nx Qx Qu bigQ Rx Ry bigR bigQ  Plqg r 
-clear Klqg Slqg Rlqg Tlqg resp title dttmax dt t n1 defv Tmax n2 u frq
-clear y w1 w2 Ptmp Pinf ro Sinf Rinf Tinf
+  clf();t=0:0.01:30;u=sin(t);
+  plot2d([t',t'],[u',(flts(u,dscr(Tlqg,0.1))')])
+  
+endfunction
+  
+demo_lqg2();
+clear demo_lqg2  
\ No newline at end of file
index 19b419f..5c65584 100644 (file)
@@ -5,15 +5,24 @@
 // This file is distributed under the same license as the Scilab package.
 //
 
+function demo_scheme()
 
-x=[5,10,20,40,50,70,80,90];xmin=-10;xmax=100;
-y=[22,28,30,32];ymin=12;ymax=40;
+  x=[5,10,20,40,50,70,80,90];xmin=-10;xmax=100;
+  y=[22,28,30,32];ymin=12;ymax=40;
 
-xx=[xmin,xmin,x([1 2 2 7 4 6 3 4 5 6 3 3 5 5]);xmax,xmax,x([3,2,7,7,5,8,3,4,5,6,4,4,6,6])];
-yy=[ymin,ymax,y([3,1,1,1,3,3,2,2,2,2,2,4,2,4]);ymin,ymax,y([3,3,1,3,3,3,4,4,4,4,2,4,2,4])];
+  xx=[xmin,xmin,x([1 2 2 7 4 6 3 4 5 6 3 3 5 5]);xmax,xmax,x([3,2,7,7,5,8,3,4,5,6,4,4,6,6])];
+  yy=[ymin,ymax,y([3,1,1,1,3,3,2,2,2,2,2,4,2,4]);ymin,ymax,y([3,3,1,3,3,3,4,4,4,4,2,4,2,4])];
     
-scf(0);clf();show_window();
-a=gca();a.data_bounds=[xmin ymin;xmax ymax];
-xpolys(xx,yy)
-xstring(28,30,'K');xstring(56,30,'Plant');xstring(12,28.80,'-');
-xtitle('PLANT   and   CONTROLLER')
+  scf(0);
+  clf();
+  show_window();
+  a=gca();
+  a.data_bounds=[xmin ymin;xmax ymax];
+  xpolys(xx,yy)
+  xstring(28,30,'K');xstring(56,30,'Plant');xstring(12,28.80,'-');
+  xtitle('PLANT   and   CONTROLLER')
+  
+endfunction
+
+demo_scheme();
+clear demo_scheme;
index e12ce66..053965e 100644 (file)
@@ -5,76 +5,82 @@
 // This file is distributed under the same license as the Scilab package.
 //
 
-mode(-1)
-lines(0);
-//display the diagram
-x=[5,10,20,40,50,70,80,90];xmin=-10;xmax=100;
-y=[22,28,30,32];ymin=12;ymax=40;
+function demo_mixed()
+  mode(-1)
+  lines(0);
+  //display the diagram
+  x=[5,10,20,40,50,70,80,90];xmin=-10;xmax=100;
+  y=[22,28,30,32];ymin=12;ymax=40;
 
-xx=[xmin,xmin,x([1 2 2 7 4 6 3 4 5 6 3 3 5 5]);xmax,xmax,x([3,2,7,7,5,8,3,4,5,6,4,4,6,6])];
-yy=[ymin,ymax,y([3,1,1,1,3,3,2,2,2,2,2,4,2,4]);ymin,ymax,y([3,3,1,3,3,3,4,4,4,4,2,4,2,4])];
+  xx=[xmin,xmin,x([1 2 2 7 4 6 3 4 5 6 3 3 5 5]);xmax,xmax,x([3,2,7,7,5,8,3,4,5,6,4,4,6,6])];
+  yy=[ymin,ymax,y([3,1,1,1,3,3,2,2,2,2,2,4,2,4]);ymin,ymax,y([3,3,1,3,3,3,4,4,4,4,2,4,2,4])];
     
-xset("window",0);clf();show_window();
-plot2d(xx,yy,ones(1,16),'022');
-xstring(28,30,'K');xstring(56,30,'Plant');xstring(12,28.80,'-');
-xtitle('PLANT   and   CONTROLLER')
-mode(2)
+  xset("window",0);clf();show_window();
+  plot2d(xx,yy,ones(1,16),'022');
+  xstring(28,30,'K');xstring(56,30,'Plant');xstring(12,28.80,'-');
+  xtitle('PLANT   and   CONTROLLER')
+  mode(2)
 
-messagebox(['Mixed Sensitivity Controller Design';
+  messagebox(['Mixed Sensitivity Controller Design';
            'file: '+SCI+'/modules/cacsd/demos/mixed.dem'],"modal");
-mode(1)
-s=poly(0,'s');
-str='[(s-1)/((s-1)^2*(s+2))]';
-rep=x_dialog('Nominal plant?',str)
-if rep==[] then return,end
-Plant=evstr(rep);Plant=syslin('c',Plant);
- //Nominal Plant
-P22=tf2ss(Plant);    //...in state-space form
-[ny,nu,nx]=size(P22);
-[Pms,r]=augment(P22);
-txt=['W1 (sensitivity function S)';'W2 (K*S)';'W3 (complementary sensitivity T)'];
-default=['s';'1';'1'];
-while %t
-  rep=x_mdialog('Set weighting functions',txt,default);
-  if rep==[] then return;end
-  W1=evstr(rep(1));W2=evstr(rep(2));W3=evstr(rep(3));
-  default=rep;
-  Pms=sysdiag(W1,W2,W3,eye(P22))*Pms;
-  gms=['gamma min= ';'gamma max= ';'# iterations'];
-  vals=['0.01';'1000';'50'];
-  reps=x_mdialog('Set interval for gamma and #iterations',gms,vals);
-  if reps==[] then return;end
-  mumin=1/evstr(reps(2))^2;
-  mumax=1/evstr(reps(1))^2;
-  iter=evstr(reps(3));
-  [K,mu]=h_inf(Pms,r,mumin,mumax,iter);
-  if K~=[] then break;end
-end
+  mode(1)
+  s=poly(0,'s');
+  str='[(s-1)/((s-1)^2*(s+2))]';
+  rep=x_dialog('Nominal plant?',str)
+  if rep==[] then return,end
+  Plant=evstr(rep);Plant=syslin('c',Plant);
+   //Nominal Plant
+  P22=tf2ss(Plant);    //...in state-space form
+  [ny,nu,nx]=size(P22);
+  [Pms,r]=augment(P22);
+  txt=['W1 (sensitivity function S)';'W2 (K*S)';'W3 (complementary sensitivity T)'];
+  default=['s';'1';'1'];
+  while %t
+    rep=x_mdialog('Set weighting functions',txt,default);
+    if rep==[] then return;end
+    W1=evstr(rep(1));W2=evstr(rep(2));W3=evstr(rep(3));
+    default=rep;
+    Pms=sysdiag(W1,W2,W3,eye(P22))*Pms;
+    gms=['gamma min= ';'gamma max= ';'# iterations'];
+    vals=['0.01';'1000';'50'];
+    reps=x_mdialog('Set interval for gamma and #iterations',gms,vals);
+    if reps==[] then return;end
+    mumin=1/evstr(reps(2))^2;
+    mumax=1/evstr(reps(1))^2;
+    iter=evstr(reps(3));
+    [K,mu]=h_inf(Pms,r,mumin,mumax,iter);
+    if K~=[] then break;end
+  end
 
-disp(spec(h_cl(Pms,r,K)),'closed loop eigenvalues')    //Check internal stability
-[Ssens,Rsens,Tsens]=sensi(P22,K);  //Sensitivity functions
-messagebox('Singular values plot',"modal");
-fcts=['S function';'R (=K*S) function';'T function'];
-www=x_mdialog('Select sensitivity function',fcts,['Yes';'No';'Yes']);
-if www==[] then return,end
+  disp(spec(h_cl(Pms,r,K)),'closed loop eigenvalues')    //Check internal stability
+  [Ssens,Rsens,Tsens]=sensi(P22,K);  //Sensitivity functions
+  messagebox('Singular values plot',"modal");
+  fcts=['S function';'R (=K*S) function';'T function'];
+  www=x_mdialog('Select sensitivity function',fcts,['Yes';'No';'Yes']);
+  if www==[] then return,end
+  
+  ww1=part(www(1),1)=='Y';
+  if ww1 then
+    scf(1);clf();show_window();
+    gainplot(Ssens);
+    xtitle('S = Sensitivity function');
+  end
 
-ww1=part(www(1),1)=='Y';
-if ww1 then
-  scf(1);clf();show_window();
-  gainplot(Ssens);
-  xtitle('S = Sensitivity function');
-end
+  ww2=part(www(2),1)=='Y';
+  if ww2 then
+    scf(2);clf();show_window();
+    gainplot(Rsens);
+    xtitle('R (=G*S) Sensitivity function');
+  end
 
-ww2=part(www(2),1)=='Y';
-if ww2 then
-  scf(2);clf();show_window();
-  gainplot(Rsens);
-  xtitle('R (=G*S) Sensitivity function');
-end
+  ww3=part(www(3),1)=='Y';
+  if ww3 then
+    scf(3);clf();show_window();
+    gainplot(Tsens);
+    xtitle('T = Complementary Sensitivity function');
+  end
 
-ww3=part(www(3),1)=='Y';
-if ww3 then
-  scf(3);clf();show_window();
-  gainplot(Tsens);
-  xtitle('T = Complementary Sensitivity function');
-end
+endfunction
+
+demo_mixed();
+clear demo_mixed;
index 945b8cd..2b66e4e 100644 (file)
@@ -36,31 +36,31 @@ function [P]=dpnd()
   teta=.25;
   r=2.5;
   P=build_pendulum([xg,y1],[lc,hc,lb,teta,r])
+
   //the floor
   xarrows([10 90],[y1-5 y1-5],0);
   xstring(90,y1,'x')
-  
+
   // the force
-  yg=y1+hc/2, 
+  yg=y1+hc/2,
   x2=xg+lc/2;
   xarrows([x2 x2+10],[yg yg],2);
   xstring(x2+20,yg,'u (force)',0,0);
-  
+
   // the vertical
   y2=y1+hc;
   xsegs([xg xg],[y2 y2+lb]);e=gce();e.line_style=2;e.segs_color=-1;
-  
+
   // the angle teta
   xstring(xg+lb*sin(teta)/2,y2+lb*cos(teta),'a',0,0);
   e=gce();e.font_size=3;
-  
+
   //the differential equations
   xstring(5,-9,['a'''' = (-sin(a)*cos(a)*(m/(m+M))*a''^2 + 2/(mb*l)*(sin(a)*m*g - qm*cos(a)*u))/d'
-               'x'''' =  (u+m*(l/2)*(sin(a)a''^2-cos(a)*a''''))/(m+M);'
-               'm: weight of the pendulum'
-               'M: weight of the cart'
-               'l: length of the pendulum'])
+        'x'''' =  (u+m*(l/2)*(sin(a)a''^2-cos(a)*a''''))/(m+M);'
+        'm: weight of the pendulum'
+        'M: weight of the cart'
+        'l: length of the pendulum'])
   drawnow()
 endfunction
 
@@ -75,7 +75,7 @@ function P=build_pendulum(o,params)
   y2=y1+hc;
   x2=xg+lc/2;
   x1=xg-lc/2;
-  
+
   //cart
   xrect([xg-lc/2,y1+hc,lc,hc]);e1=gce();
   xfarcs([x1+lc/10-r;y1;2*r;2*r;0;360*64],1);e2=gce();
@@ -87,7 +87,7 @@ function P=build_pendulum(o,params)
   P=glue([e4 e3 e2 e1])
   P.user_data=[xg,lb]
 endfunction
+
 function P=set_pendulum(P,x,theta)
   p=P.user_data
   xg=p(1);lb=p(2);
@@ -97,7 +97,7 @@ function P=set_pendulum(P,x,theta)
   e=P.children(2).children;e.data(1)=e.data(1)+x-xg;
   e=P.children(3).children;e.data(1)=e.data(1)+x-xg;
   e=P.children(4);e.data(:,1)=e.data(:,1)+x-xg;
-  
+
    //change the pendulum angle
   e.data(2,:)=e.data(1,:)+[lb*sin(theta) lb*cos(theta)];
   P.user_data(1)=x
@@ -169,7 +169,7 @@ function draw2()
   theta = yd(3,:) //angle
   thetaE= yd(7,:) // estimated angle
   x = yd(1,:)
-  
+
   a1=gca();sca(a1);
   a1.axes_bounds=[0 0 0.5 0.5];
   a1.data_bounds=[min(t1),min(c);t1(n) max(c)];
@@ -213,5 +213,5 @@ function draw2()
     P=set_pendulum(P,xx,tt);
   end
   //f.pixmap='off'
-  
+
 endfunction
index 943501c..732e41e 100644 (file)
 // This file is distributed under the same license as the Scilab package.
 //
 
-mode(-1)
-path=get_absolute_file_path('pendule.dem');
-
-exec(path+'simulation.sci')
-exec(path+'graphics.sci')
-
-//disable displayed lines control
-display_props=lines(); lines(0)
-my_handle             = scf(100001);
-clf(my_handle,"reset");
-
-show_window();
-wdim=xget('wdim')
-//mode(1)
-
- dpnd()
-
-//
-// equations 
-//----------
-//state =[x x' theta theta']  
-//
- mb=0.1;mc=1;l=0.3;m=4*mc+mb; //constants
-//
-messagebox(['Open loop simulation'
-          ' '
-          ' y0 = [0;0;0.1;0]; //initial state [x x'' theta theta'']'
-          ' t = 0.03*(1:180); //observation dates'
-          ' y = ode(y0,0,0.03*(1:180),ivpd); //differential equation integration'
-          ' //Display'
-          ' P = initialize_display(y0(1),y0(3))'
-          ' for k=1:size(y,2), set_pendulum(P,y(1,k),y(3,k));end'],"modal");
-//
- y0=[0;0;0.1;0];
- y=ode(y0,0,0.03*(1:180),ivpd);
-
- P=initialize_display(y0(1),y0(3));
- for k=1:size(y,2), set_pendulum(P,y(1,k),y(3,k));end
-//
-messagebox(['Linearization'
-          ' '
-          ' x0=[0;0;0;0];u0=0;'
-          ' [f,g,h,j]=lin(pendu,x0,u0);'
-          ' pe=syslin(''c'',f,g,h,j);'
-          ' // display of the linear system'
-          ' ssprint(pe)'],"modal")
-
-//
-mode(1)
- x0=[0;0;0;0];u0=0;
- [f,g,h,j]=lin(pendu,x0,u0);
- pe=syslin('c',f,g,h,j);
- ssprint(pe)
-mode(-1)
-//
-messagebox(['Checking the result'
-          ' //comparison with linear model computed by hand';
-          ''
-          ' f1=[0 1        0                0'
-          '     0 0    -3*mb*9.81/m         0'
-          '     0 0        0                1'
-          '     0 0  6*(mb+mc)*9.81/(m*l)   0];'
-          ' '
-          ' g1=[0 ; 4/m ; 0 ; -6/(m*l)];'
-          ' '
-          ' h1=[1 0 0 0'
-          '     0 0 1 0];'
-          ' '
-          ' err=norm(f-f1,1)+norm(g-g1,1)+norm(h-h1,1)+norm(j,1)'],"modal")
-
-//
-mode(1)
- f1=[0 1        0             0
+function demo_pendule()
+
+    mode(-1)
+
+
+    exec("SCI/modules/cacsd/demos/pendulum/simulation.sci", -1);
+    exec("SCI/modules/cacsd/demos/pendulum/graphics.sci", -1);
+
+    //disable displayed lines control
+    display_props=lines(); lines(0)
+    my_handle             = scf(100001);
+    clf(my_handle,"reset");
+
+    show_window();
+    wdim=xget('wdim')
+    //mode(1)
+
+    dpnd()
+
+    //
+    // equations 
+    //----------
+    //state =[x x' theta theta']  
+    //
+    mb=0.1;mc=1;l=0.3;m=4*mc+mb; //constants
+    //
+    messagebox(['Open loop simulation'
+    ' '
+    ' y0 = [0;0;0.1;0]; //initial state [x x'' theta theta'']'
+    ' t = 0.03*(1:180); //observation dates'
+    ' y = ode(y0,0,0.03*(1:180),ivpd); //differential equation integration'
+    ' //Display'
+    ' P = initialize_display(y0(1),y0(3))'
+    ' for k=1:size(y,2), set_pendulum(P,y(1,k),y(3,k));end'],"modal");
+    //
+    y0=[0;0;0.1;0];
+    y=ode(y0,0,0.03*(1:180),ivpd);
+
+    P=initialize_display(y0(1),y0(3));
+    for k=1:size(y,2), set_pendulum(P,y(1,k),y(3,k));end
+    //
+    messagebox(['Linearization'
+    ' '
+    ' x0=[0;0;0;0];u0=0;'
+    ' [f,g,h,j]=lin(pendu,x0,u0);'
+    ' pe=syslin(''c'',f,g,h,j);'
+    ' // display of the linear system'
+    ' ssprint(pe)'],"modal")
+
+    //
+    mode(1)
+    x0=[0;0;0;0];u0=0;
+    [f,g,h,j]=lin(pendu,x0,u0);
+    pe=syslin('c',f,g,h,j);
+    ssprint(pe)
+    mode(-1)
+
+    //
+    messagebox(['Checking the result'
+    ' //comparison with linear model computed by hand';
+    ''
+    ' f1=[0 1        0                0'
+    '     0 0    -3*mb*9.81/m         0'
+    '     0 0        0                1'
+    '     0 0  6*(mb+mc)*9.81/(m*l)   0];'
+    ' '
+    ' g1=[0 ; 4/m ; 0 ; -6/(m*l)];'
+    ' '
+    ' h1=[1 0 0 0'
+    '     0 0 1 0];'
+    ' '
+    ' err=norm(f-f1,1)+norm(g-g1,1)+norm(h-h1,1)+norm(j,1)'],"modal")
+
+
+    //
+    mode(1)
+    f1=[0 1        0             0
     0 0    -3*mb*9.81/m         0
     0 0        0             1
     0 0  6*(mb+mc)*9.81/(m*l)   0];
- g1=[0 ; 4/m ; 0 ; -6/(m*l)];
- h1=[1 0 0 0
-     0 0 1 0];
- err=norm(f-f1,1)+norm(g-g1,1)+norm(h-h1,1)+norm(j,1)
- mode(-1)
-messagebox(['Linear system properties analysis'
-          ' spec(f) //stability (unstable system !)'
-          ' n=contr(f,g) //controlability'
-          ' '
-          ' //observability'
-          ' m1=contr(f'',h(1,:)'') '
-          ' [m2,t]=contr(f'',h(2,:)'')'],"modal");
-//---------
-mode(1)
- spec(f) //stability (unstable system !)
- n=contr(f,g) //controlability
-
- //observability
- m1=contr(f',h(1,:)') 
- [m2,t]=contr(f',h(2,:)')
- mode(-1)
-//
-messagebox(['Synthesis of a stabilizing controller using poles placement'
-          ' '
-          '// only x and theta are observed  : contruction of an observer'
-          '// to estimate the state : z''=(f-k*h)*z+k*y+g*u'
-          ' to=0.1; ' 
-          ' k=ppol(f'',h'',-ones(4,1)/to)''  //observer gain'
-          '// compute the compensator gain'
-          ' kr=ppol(f,g,-ones(4,1)/to)'],"modal");
-
-//-------------------------------------------------
-//
-//pole placement technique
-//only x and theta are observed  : contruction of an observer
-//to estimate the state : z'=(f-k*h)*z+k*y+g*u
-//
- to=0.1;  //
- k=ppol(f',h',-ones(4,1)/to)'  //observer gain
-//
-//verification
-//
-// norm( poly(f-k*h,'z')-poly(-ones(4,1)/to,'z'))
-//
- kr=ppol(f,g,-ones(4,1)/to)  //compensator gain
-//
-messagebox(['Build full linear system  pendulum-observer-compensator'
-          ' '
-          ' ft=[f-g*kr            -g*kr'
-          '     0*f               f-k*h]'
-          ' '
-          ' gt=[g;0*g];'
-          ' ht=[h,0*h];'
-          ''
-          ' pr=syslin(''c'',ft,gt,ht);'
-          ''
-          '//Check the closed loop dynamic'
-          ' spec(pr.A)'
-          ' '
-          '//transfer matrix representation'
-          ' hr=clean(ss2tf(pr),1.d-10)'
-          ' '
-          '//frequency analysis'
-          ' black(pr,0.01,100,[''position'',''theta''])'
-          ' g_margin(pr(1,1))'],"modal");
-
-//---------------------------------------------
-//
-//state: [x x-z]
-//
-mode(1)
- ft=[f-g*kr            -g*kr
-      0*f               f-k*h];
- gt=[g;0*g];
- ht=[h,0*h];
- pr=syslin('c',ft,gt,ht);
-
-// closed loop dynamics:
- spec(pr(2))
-//transfer matrix representation
- hr=clean(ss2tf(pr),1.d-10)
- //frequency analysis
- clf()
- black(pr,0.01,100,['position','theta'])
- g_margin(pr(1,1))
- show_pixmap()
- mode(-1)
-//
-messagebox(['Sampled system'
-          ' '
-          ' t=to/5; //sampling period'
-          ' prd=dscr(pr,t); //discrete model'
-          ' spec(prd.A) //poles of the discrete model'],"modal");
-
-//---------------
-//
-mode(1)
- t=to/5;
- prd=dscr(pr,t);
- spec(prd(2))
-mode(-1)
-//
-messagebox(['Impulse response'
-          ' '
-          ' x0=[0;0;0;0;0;0;0;0]; //initial state'
-          ' u(1,180)=0;u(1,1)=1; //impulse'
-          ' y=flts(u,prd,x0);    //siscrete system simulation'
-          ' draw1()'],"modal");
-
-//-----------------
-//
-mode(1)
- x0=[0;0;0;0;0;0;0;0];
- u(1,180)=0;u(1,1)=1;
- y=flts(u,prd,x0);
-
- draw1()
-mode(-1)
-//
-messagebox(['Compensation of the non linear system with'
-          'linear regulator'
-          ''
-          ' t0=0;t1=t*(1:125);'
-          ' x0=[0 0 0.4 0   0 0 0 0]'';  // initial state'
-          ' yd=ode(x0,t0,t1,regu); //integration of differential equation'
-          ' draw2()'],"modal");
-;
-//--------------------------------------
-//
-//simulation
-//
-mode(1)
- t0=0;t1=t*(1:125);
- x0=[0 0 0.4 0   0 0 0 0]';   //
- yd=ode(x0,t0,t1,regu);
- draw2()
-mode(-1) 
-lines(display_props(2))
-messagebox('The end',"modal");
+    g1=[0 ; 4/m ; 0 ; -6/(m*l)];
+    h1=[1 0 0 0
+    0 0 1 0];
+    err=norm(f-f1,1)+norm(g-g1,1)+norm(h-h1,1)+norm(j,1)
+    mode(-1)
+
+    messagebox(['Linear system properties analysis'
+    ' spec(f) //stability (unstable system !)'
+    ' n=contr(f,g) //controlability'
+    ' '
+    ' //observability'
+    ' m1=contr(f'',h(1,:)'') '
+    ' [m2,t]=contr(f'',h(2,:)'')'],"modal");
+    //---------
+    mode(1)
+    spec(f) //stability (unstable system !)
+    n=contr(f,g) //controlability
+
+    //observability
+    m1=contr(f',h(1,:)') 
+    [m2,t]=contr(f',h(2,:)')
+    mode(-1)
+    //
+    messagebox(['Synthesis of a stabilizing controller using poles placement'
+    ' '
+    '// only x and theta are observed  : contruction of an observer'
+    '// to estimate the state : z''=(f-k*h)*z+k*y+g*u'
+    ' to=0.1; ' 
+    ' k=ppol(f'',h'',-ones(4,1)/to)''  //observer gain'
+    '// compute the compensator gain'
+    ' kr=ppol(f,g,-ones(4,1)/to)'],"modal");
+
+    //-------------------------------------------------
+    //
+    //pole placement technique
+    //only x and theta are observed  : contruction of an observer
+    //to estimate the state : z'=(f-k*h)*z+k*y+g*u
+    //
+    to=0.1;  //
+    k=ppol(f',h',-ones(4,1)/to)'  //observer gain
+    //
+    //verification
+    //
+    // norm( poly(f-k*h,'z')-poly(-ones(4,1)/to,'z'))
+    //
+    kr=ppol(f,g,-ones(4,1)/to)  //compensator gain
+
+    //
+    messagebox(['Build full linear system  pendulum-observer-compensator'
+    ' '
+    ' ft=[f-g*kr            -g*kr'
+    '     0*f               f-k*h]'
+    ' '
+    ' gt=[g;0*g];'
+    ' ht=[h,0*h];'
+    ''
+    ' pr=syslin(''c'',ft,gt,ht);'
+    ''
+    '//Check the closed loop dynamic'
+    ' spec(pr.A)'
+    ' '
+    '//transfer matrix representation'
+    ' hr=clean(ss2tf(pr),1.d-10)'
+    ' '
+    '//frequency analysis'
+    ' black(pr,0.01,100,[''position'',''theta''])'
+    ' g_margin(pr(1,1))'],"modal");
+
+    //---------------------------------------------
+    //
+    //state: [x x-z]
+    //
+    mode(1)
+    ft=[f-g*kr            -g*kr
+    0*f               f-k*h];
+    gt=[g;0*g];
+    ht=[h,0*h];
+    pr=syslin('c',ft,gt,ht);
+
+    // closed loop dynamics:
+    spec(pr(2))
+    //transfer matrix representation
+    hr=clean(ss2tf(pr),1.d-10)
+
+
+    //frequency analysis
+    clf()
+    black(pr,0.01,100,['position','theta'])
+    g_margin(pr(1,1))
+    show_pixmap()
+    mode(-1)
+
+
+    //
+    messagebox(['Sampled system'
+    ' '
+    ' t=to/5; //sampling period'
+    ' prd=dscr(pr,t); //discrete model'
+    ' spec(prd.A) //poles of the discrete model'],"modal");
+
+    //---------------
+    //
+    mode(1)
+    t=to/5;
+    prd=dscr(pr,t);
+    spec(prd(2))
+    mode(-1)
+    //
+    messagebox(['Impulse response'
+    ' '
+    ' x0=[0;0;0;0;0;0;0;0]; //initial state'
+    ' u(1,180)=0;u(1,1)=1; //impulse'
+    ' y=flts(u,prd,x0);    //siscrete system simulation'
+    ' draw1()'],"modal");
+
+    //-----------------
+    //
+    mode(1)
+    x0=[0;0;0;0;0;0;0;0];
+    u(1,180)=0;u(1,1)=1;
+    y=flts(u,prd,x0);
+
+    draw1()
+    mode(-1)
+    //
+    messagebox(['Compensation of the non linear system with'
+    'linear regulator'
+    ''
+    ' t0=0;t1=t*(1:125);'
+    ' x0=[0 0 0.4 0   0 0 0 0]'';  // initial state'
+    ' yd=ode(x0,t0,t1,regu); //integration of differential equation'
+    ' draw2()'],"modal");
+    ;
+    //--------------------------------------
+    //
+    //simulation
+    //
+    mode(1)
+    t0=0;t1=t*(1:125);
+    x0=[0 0 0.4 0   0 0 0 0]';   //
+    yd=ode(x0,t0,t1,regu);
+    draw2()
+    mode(-1) 
+    lines(display_props(2))
+    messagebox('The end',"modal");
+endfunction
+
+demo_pendule();
+clear demo_pendule;
\ No newline at end of file
index a2030d9..09545b3 100644 (file)
@@ -10,7 +10,7 @@
 function [xdot]=ivpd(t,x)
 //ydot=ivpd(t,y) non linear equations of the pendulum
 // y=[x;d(x)/dt,teta,d(teta)/dt].
-// mb, mc, l must be predefined 
+// mb, mc, l must be predefined
 //!
 g=9.81;
 u=0
index 1dcbd89..22c9c09 100644 (file)
 // This file is distributed under the same license as the Scilab package.
 //
 
-mode(-1);
-lines(0);
-//display the diagram
-x=[5,10,20,40,50,70,80,90];xmin=-10;xmax=100;
-y=[22,28,30,32];ymin=12;ymax=40;
+function demo_pid()
 
-xx=[xmin,xmin,x([1 2 2 7 4 6 3 4 5 6 3 3 5 5]);xmax,xmax,x([3,2,7,7,5,8,3,4,5,6,4,4,6,6])];
-yy=[ymin,ymax,y([3,1,1,1,3,3,2,2,2,2,2,4,2,4]);ymin,ymax,y([3,3,1,3,3,3,4,4,4,4,2,4,2,4])];
+  mode(-1);
+  lines(0);
+  //display the diagram
+  x=[5,10,20,40,50,70,80,90];xmin=-10;xmax=100;
+  y=[22,28,30,32];ymin=12;ymax=40;
 
-xset("window",0);clf();show_window();
-plot2d(xx,yy,ones(1,16),'022');
-xstring(28,30,'K');xstring(56,30,'Plant');xstring(12,28.80,'-');
-xtitle('PLANT   and   CONTROLLER')
-mode(2);
+  xx=[xmin,xmin,x([1 2 2 7 4 6 3 4 5 6 3 3 5 5]);xmax,xmax,x([3,2,7,7,5,8,3,4,5,6,4,4,6,6])];
+  yy=[ymin,ymax,y([3,1,1,1,3,3,2,2,2,2,2,4,2,4]);ymin,ymax,y([3,3,1,3,3,3,4,4,4,4,2,4,2,4])];
 
-s=poly(0,'s');z=poly(0,'z');
-messagebox(['Example of PID Design '
-            'file: '+SCI+'/modules/cacsd/demos/pid.dem'],"modal");
+  xset("window",0);clf();show_window();
+  plot2d(xx,yy,ones(1,16),'022');
+  xstring(28,30,'K');xstring(56,30,'Plant');xstring(12,28.80,'-');
+  xtitle('PLANT   and   CONTROLLER')
+  mode(2);
 
-n=x_choose(['Continuous time';'Discrete time'],'Select time domain');
-select n
- case 0
-  warning('Demo stops!');return;
- case 1
-  mode(1)
-  dom='c';
-  s=poly(0,'s');
-  str='[(s-1)/(s^2+5*s+1)]';
-  rep=x_dialog('Nominal plant?',str);
-  if rep==[] then return,end
-  Plant=evstr(rep);
-  Plant=syslin('c',Plant);
-  mode(-1)
-case 2
-  mode(1)
-  dom='d'
-  z=poly(0,'z');
-  str='(z+1)/(z^2-5*z+2)'
-  rep=x_dialog('Nominal plant?',str);
-  if rep==[] then return,end
-  Plant=evstr(rep)
-  Plant=syslin('d',Plant);
-  mode(-1)
-end
-//Nominal Plant
-P22=tf2ss(Plant);    //...in state-space form
-[ny,nu,nx]=size(P22);
-defv=['-1.2';'1';'0.1'];
-if dom=='d' then defv=['-10';'1';'0.1'];end
-while %t
-  mode(1)
-  if dom=='c' then
-    _title='Enter your PID controller K(s)=Kp*(1+T0/s+T1*s)';
-  end
-  if dom=='d' then
-    _title='Enter your PID controller K(z)=Kp*(1+T0/z+T1*z)';
-  end
-  defv=x_mdialog(_title,['Kp=';'T0=';'T1='],defv);
-  if defv==[] then warning('Demo stops!');return;end
-  Kp=evstr(defv(1));T0=evstr(defv(2));T1=evstr(defv(3));
-  if dom=='c' then
-    Kpid=tf2ss(Kp*(1+T0/s+T1*s));
-  end
-  if dom=='d' then
-    Kpid=tf2ss(Kp*(1+T0/z+T1*z));
-  end
-  W=[1, -P22;
-      Kpid,1];Winv=inv(W);
-
-  disp(spec(Winv(2)),'closed loop eigenvalues');//Check internal stability
-  if max(real(spec(Winv(2)))) > 0 then 
-    messagebox('You loose: closed-loop is UNSTABLE!!!',"modal");
-  else
-    messagebox('Congratulations: closed-loop is STABLE !!!',"modal");
-    break;
-  end
-  mode(-1)
-end
-mode(1)
-[Spid,Rpid,Tpid]=sensi(P22,Kpid);  //Sensitivity functions
-Tpid(5)=clean(Tpid(5));
-
-disp(clean(ss2tf(Spid)),'Sensitivity function');
-disp(clean(ss2tf(Tpid)),'Complementary sensitivity function');
-
-resp=['Frequency response';'Time response'];
-while %t do
-  n=x_choose(resp,'Select response(s)');
-  if degree(Tpid(5))>0 then
-    warning('Improper transfer function! D(s) set to D(0)')
-    Tpid(5)=coeff(Tpid(5),0);
-  end
-  Tpid(5)=coeff(Tpid(5));
+  s=poly(0,'s');z=poly(0,'z');
+  messagebox(['Example of PID Design '
+              'file: '+SCI+'/modules/cacsd/demos/pid.dem'],"modal");
+  
+  n=x_choose(['Continuous time';'Discrete time'],'Select time domain');
   select n
-  case 0
-    break
-  case 1
+   case 0
+    warning('Demo stops!');return;
+   case 1
     mode(1)
-    clf(1);xset("window",1);show_window();bode(Tpid);
+    dom='c';
+    s=poly(0,'s');
+    str='[(s-1)/(s^2+5*s+1)]';
+    rep=x_dialog('Nominal plant?',str);
+    if rep==[] then return,end
+    Plant=evstr(rep);
+    Plant=syslin('c',Plant);
     mode(-1)
   case 2
-    if Plant(4)=='c' then
-      mode(1)
-      defv=['0.1';'50'];
-      _title='Enter Sampling period and Tmax';
-      rep=x_mdialog(_title,['Sampling period?';'Tmax?'],defv);
-      if rep==[] then break,end
-      dttmax=evstr(rep);
-      dt=evstr(dttmax(1));tmax=evstr(dttmax(2));
-      t=0:dt/5:tmax;
-      n1=x_choose(['Step response?';'Impulse response?'],'Simulation:');
-      if n1==0 then
-        warning('Demo stops!');return;
-      end
-      if n1==1 then 
-        clf(1);xset("window",1);show_window();
-        plot2d([t',t'],[(csim('step',t,Tpid))',ones(t')])
-      end
-      if n1==2 then
-        clf(1);xset("window",1);show_window();
-        plot2d([t',t'],[(csim('impul',t,Tpid))',0*t'])
-      end
-      mode(-1)
-    elseif Plant(4)=='d' then
+    mode(1)
+    dom='d'
+    z=poly(0,'z');
+    str='(z+1)/(z^2-5*z+2)'
+    rep=x_dialog('Nominal plant?',str);
+    if rep==[] then return,end
+    Plant=evstr(rep)
+    Plant=syslin('d',Plant);
+    mode(-1)
+  end
+  //Nominal Plant
+  P22=tf2ss(Plant);    //...in state-space form
+  [ny,nu,nx]=size(P22);
+  defv=['-1.2';'1';'0.1'];
+  if dom=='d' then defv=['-10';'1';'0.1'];end
+  while %t
+    mode(1)
+    if dom=='c' then
+      _title='Enter your PID controller K(s)=Kp*(1+T0/s+T1*s)';
+    end
+    if dom=='d' then
+      _title='Enter your PID controller K(z)=Kp*(1+T0/z+T1*z)';
+    end
+    defv=x_mdialog(_title,['Kp=';'T0=';'T1='],defv);
+    if defv==[] then warning('Demo stops!');return;end
+    Kp=evstr(defv(1));T0=evstr(defv(2));T1=evstr(defv(3));
+    if dom=='c' then
+      Kpid=tf2ss(Kp*(1+T0/s+T1*s));
+    end
+    if dom=='d' then
+      Kpid=tf2ss(Kp*(1+T0/z+T1*z));
+    end
+    W=[1, -P22;
+        Kpid,1];Winv=inv(W);
+  
+    disp(spec(Winv(2)),'closed loop eigenvalues');//Check internal stability
+    if max(real(spec(Winv(2)))) > 0 then 
+      messagebox('You loose: closed-loop is UNSTABLE!!!',"modal");
+    else
+      messagebox('Congratulations: closed-loop is STABLE !!!',"modal");
+      break;
+    end
+    mode(-1)
+  end
+  mode(1)
+  [Spid,Rpid,Tpid]=sensi(P22,Kpid);  //Sensitivity functions
+  Tpid(5)=clean(Tpid(5));
+  
+  disp(clean(ss2tf(Spid)),'Sensitivity function');
+  disp(clean(ss2tf(Tpid)),'Complementary sensitivity function');
+  
+  resp=['Frequency response';'Time response'];
+  while %t do
+    n=x_choose(resp,'Select response(s)');
+    if degree(Tpid(5))>0 then
+      warning('Improper transfer function! D(s) set to D(0)')
+      Tpid(5)=coeff(Tpid(5),0);
+    end
+    Tpid(5)=coeff(Tpid(5));
+    select n
+    case 0
+      break
+    case 1
       mode(1)
-      defv=['100'];
-      _title='Tmax?'
-      rep=x_mdialog(_title,['Tmax='],defv);
-      if rep==[] then break,end
-      Tmax=evstr(rep);
+      clf(1);xset("window",1);show_window();bode(Tpid);
       mode(-1)
-      while %t do
-        n=x_choose(['Step response?';'Impulse response?'],'Simulation:');
-        select n
-        case 0 then
-          break
-        case 1 then
-          mode(1)
-          u=ones(1,Tmax);u(1)=0;
+    case 2
+      if Plant(4)=='c' then
+        mode(1)
+        defv=['0.1';'50'];
+        _title='Enter Sampling period and Tmax';
+        rep=x_mdialog(_title,['Sampling period?';'Tmax?'],defv);
+        if rep==[] then break,end
+        dttmax=evstr(rep);
+        dt=evstr(dttmax(1));tmax=evstr(dttmax(2));
+        t=0:dt/5:tmax;
+        n1=x_choose(['Step response?';'Impulse response?'],'Simulation:');
+        if n1==0 then
+          warning('Demo stops!');return;
+        end
+        if n1==1 then 
           clf(1);xset("window",1);show_window();
-          plot2d([(1:Tmax)',(1:Tmax)'],[(dsimul(Tpid,u))',(ones(1:Tmax)')])
-          mode(-1)
-        case 2 then
-          mode(1)
-          u=zeros(1,Tmax);u(1)=1;
+          plot2d([t',t'],[(csim('step',t,Tpid))',ones(t')])
+        end
+        if n1==2 then
           clf(1);xset("window",1);show_window();
-          plot2d((1:Tmax)',(dsimul(Tpid,u))')
-          mode(-1)
+          plot2d([t',t'],[(csim('impul',t,Tpid))',0*t'])
+        end
+        mode(-1)
+      elseif Plant(4)=='d' then
+        mode(1)
+        defv=['100'];
+        _title='Tmax?'
+        rep=x_mdialog(_title,['Tmax='],defv);
+        if rep==[] then break,end
+        Tmax=evstr(rep);
+        mode(-1)
+        while %t do
+          n=x_choose(['Step response?';'Impulse response?'],'Simulation:');
+          select n
+          case 0 then
+            break
+          case 1 then
+            mode(1)
+            u=ones(1,Tmax);u(1)=0;
+            clf(1);xset("window",1);show_window();
+            plot2d([(1:Tmax)',(1:Tmax)'],[(dsimul(Tpid,u))',(ones(1:Tmax)')])
+            mode(-1)
+          case 2 then
+            mode(1)
+            u=zeros(1,Tmax);u(1)=1;
+            clf(1);xset("window",1);show_window();
+            plot2d((1:Tmax)',(dsimul(Tpid,u))')
+            mode(-1)
+          end
         end
       end
     end
   end
-end
+endfunction
+
+demo_pid();
+clear demo_pid;
\ No newline at end of file
index 541ced5..707960a 100644 (file)
@@ -179,7 +179,7 @@ function create_frame(my_fig_handle,fr_position,fr_title,fr_items)
                "fontsize"            , 12,...
                "horizontalalignment" , "left", ...
                "BackgroundColor"     , [255/255 , 255/255 , 255/255 ], ...
-               "callback"            , "script_path = demo_gui_update();exec(script_path,-1);",...
+               "callback"            , "script_path = demo_gui_update();exec(script_path,-1);clear script_path;",...
                "visible"             , my_visible, ...
                "user_data"           , fr_items, ...
                "tag"                 , "listbox_"+string(fr_position));
index 1ac6cda..17009da 100644 (file)
@@ -1,6 +1,7 @@
 //
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2008 - INRIA - Pierre MARECHAL
+// Copyright (C) 2010 - DIGITEO - Allan CORNET
 //
 // This file must be used under the terms of the CeCILL.
 // This source file is licensed as described in the file COPYING, which
 //
 
 function demo_viewCode(this_script)
-       
-       if (~isdef('editor') & (funptr('editor')==0)) then
-         return
-       end
-       
-       path = get_absolute_file_path(this_script)+this_script;
-       
-       // Récupération du handle sur la fenêtre courante
-       my_fig = gcf();
-       
-       //Création du nouveau menu
-       my_menu = uimenu( "parent"          , my_fig                       , ..
-           "label"           , gettext(" -- View Code -- ") , ..
-           "Foregroundcolor" , [ 0/255 81/255 6/255 ]       , ..
-           "callback"        , "editor("""+path+""", ""readonly"")" );
-       
+
+  if (~isdef('editor') & (funptr('editor')==0)) then
+    return
+  end
+
+  if isfile(this_script) then
+    path = fullpath(this_script);
+  else
+    path = get_absolute_file_path(this_script) + this_script;
+  end
+
+  // Récupération du handle sur la fenêtre courante
+  my_fig = gcf();
+
+  //Création du nouveau menu
+  my_menu = uimenu( "parent"      , my_fig             , ..
+    "label"       , gettext(" -- View Code -- ") , ..
+    "Foregroundcolor" , [ 0/255 81/255 6/255 ]     , ..
+    "callback"    , "editor("""+path+""", ""readonly"")" );
+
 endfunction
+
index 4efd309..c37ff6e 100644 (file)
@@ -9,3 +9,4 @@ subdemolist = ["unstable trajectory"  , "bike1.dem.sce" ; ..
                "stable trajectory!"   , "bike2.dem.sce" ];
 
 subdemolist(:,2) = demopath + subdemolist(:,2);
+clear demopath;
\ No newline at end of file
index 4f86036..2131e07 100644 (file)
@@ -1,6 +1,7 @@
 //
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) INRIA
+// Copyright (C) DIGITEO - 2010 - Allan CORNET
 //
 // This file is distributed under the same license as the Scilab package.
 //
@@ -24,7 +25,7 @@ function []=velo1()
   curAxe.rotation_angles = [82,-3];
   curAxe.title.text      = _("bike simulation, stable trajectory")
   curAxe.title.font_size = 3;
-  
+
   // The floor
   xfpoly([xmin xmax xmax xmin xmin],[ymin ymin ymax ymax ymin])
   e=gce();
@@ -46,7 +47,7 @@ function []=velo1()
   drawnow()
 
   // animation
-  if ~isdef('velo_rti') then   velo_rti=0.05;end 
+  if ~isdef('velo_rti') then   velo_rti=0.05;end
   realtimeinit(velo_rti);
   realtime(0)
 
@@ -54,16 +55,32 @@ function []=velo1()
   show_pixmap();
 
   for i=2:1:n2
-    
+
     realtime(i);
+
+    if ~is_handle_valid(curAxe) then
+      break;
+    end
+
     drawlater();
-    e1.data     = [xfrontar(:,i) yfrontar(:,i) zfrontar(:,i)];
-    e2.data     = [xrearar(:,i)  yrearar(:,i)  zrearar(:,i) ];
-    e3.data     = [xf(:,i) yf(:,i) zf(:,i)];
-    erear.data  = [erear.data;
-                  xprear(1,i),xprear(2,i),xprear(3,i)];
-//    efront.data = [efront.data;
-//                xpfront(1,i),xpfront(2,i),xpfront(3,i)];
+
+    if is_handle_valid(e1) then
+      e1.data     = [xfrontar(:,i) yfrontar(:,i) zfrontar(:,i)];
+    end
+
+    if is_handle_valid(e2) then
+      e2.data     = [xrearar(:,i)  yrearar(:,i)  zrearar(:,i) ];
+    end
+
+    if is_handle_valid(e3) then
+      e3.data     = [xf(:,i) yf(:,i) zf(:,i)];
+    end
+
+    if is_handle_valid(erear) then
+      erear.data  = [erear.data;
+           xprear(1,i),xprear(2,i),xprear(3,i)];
+    end
+
     drawnow();
 
   end
index a84ba5d..7ab6326 100644 (file)
@@ -1,6 +1,7 @@
 //
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) INRIA
+// Copyright (C) DIGITEO - 2010 - Allan CORNET
 //
 // This file is distributed under the same license as the Scilab package.
 //
@@ -23,19 +24,19 @@ function []=velo4p()
   curAxe.rotation_angles = [t p];
   curAxe.title.text      = _("bike simulation, unstable trajectory");
   curAxe.title.font_size = 3;
-  
+
   // The floor
   xfpoly([xmin xmax xmax xmin xmin],[ymin ymin ymax ymax ymin])
   e=gce();
   e.background    = color('lightgray');
 
+
   // Add decorations for fun
   poteau(xmin,(ymin+ymax)/2,0.4,0.4)
   arbre(xmax,ymax,0.1,0.1)
   arbre((xmax+xmin)/2,(ymin+ymax)/2,0.1,0.1)
 
-  
+
   [n1,n2]=size(xfrontar);
   // Build the bicycle graphical objects
   e3=poly3d(xf(:,1),yf(:,1),zf(:,1))
@@ -49,22 +50,44 @@ function []=velo4p()
   // front trace
   efront = poly3d(xpfront(1,1),xpfront(2,1),xpfront(3,1))
   drawnow()
-  
+
   // animation
-  if ~isdef('velo_rti') then   velo_rti=0.03; end 
+  if ~isdef('velo_rti') then   velo_rti=0.03; end
   realtimeinit(velo_rti);
   realtime(1)
 
   for i=1:1:n2
+
+    if ~is_handle_valid(curAxe) then
+      break;
+    end
+
     realtime(i);
+
     drawlater();
-    e1.data     = [xfrontar(:,i) yfrontar(:,i) zfrontar(:,i)];
-    e2.data     = [xrearar(:,i)  yrearar(:,i)  zrearar(:,i) ];
-    e3.data     = [xf(:,i) yf(:,i) zf(:,i)];
-    erear.data  = [erear.data;
-                  xprear(1,i),xprear(2,i),xprear(3,i)];
-    efront.data = [efront.data;
-                  xpfront(1,i),xpfront(2,i),xpfront(3,i)];
+
+    if is_handle_valid(e1) then
+      e1.data     = [xfrontar(:,i) yfrontar(:,i) zfrontar(:,i)];
+    end
+
+    if is_handle_valid(e2) then
+      e2.data     = [xrearar(:,i)  yrearar(:,i)  zrearar(:,i) ];
+    end
+
+    if is_handle_valid(e3) then
+      e3.data     = [xf(:,i) yf(:,i) zf(:,i)];
+    end
+
+    if is_handle_valid(erear) then
+      erear.data  = [erear.data;
+           xprear(1,i),xprear(2,i),xprear(3,i)];
+    end
+
+    if is_handle_valid(efront) then
+      efront.data = [efront.data;
+           xpfront(1,i),xpfront(2,i),xpfront(3,i)];
+    end
+    
     drawnow();
   end
 
@@ -72,14 +95,14 @@ endfunction
 
 function []=poteau(xcenter,ycenter,xep,yep)
 // rajoute un poteau de centre xcenter,ycenter)
-// d'epaisseur xep et yep 
+// d'epaisseur xep et yep
 //!
 // Comment rajouter un petit cube
   xc=[xcenter-xep*1.001,xcenter-xep*0.999,xcenter+xep*0.999,xcenter+xep*1.001];
   yc=[ycenter-yep*1.001,ycenter-yep*0.999,ycenter+yep*0.999,ycenter+yep*1.001];
   zmat=zmin*ones(4,4);
   zmat(2:3,2:3)=zmax*ones(2,2);
-  // grise du poteau 
+  // grise du poteau
     potg=10
   plot3d(xc,yc,zmat,t,p," ",[potg,0,0]);
 endfunction
@@ -87,14 +110,14 @@ endfunction
 
 function []=arbre(xcenter,ycenter,xep,yep)
 // rajoute un poteau de centre xcenter,ycenter)
-// d'epaisseur xep et yep 
+// d'epaisseur xep et yep
 //!
 // Comment rajouter un petit cube
   xc=[xcenter-xep*1.001,xcenter-xep*0.999,xcenter+xep*0.999,xcenter+xep*1.001];
   yc=[ycenter-yep*1.001,ycenter-yep*0.999,ycenter+yep*0.999,ycenter+yep*1.001];
   zmat=zmin*ones(4,4);
   zmat(2:3,2:3)=zmax*ones(2,2);
-  // grise du poteau 
+  // grise du poteau
   potg=10
   plot3d(xc,yc,zmat,t,p," ",[potg,0,0]);
   rand('uniform');
index d553d29..45a6582 100644 (file)
@@ -9,3 +9,4 @@ subdemolist = ["Spherical pendulum" ,"dae1/pend3d1.dem.sce" ;
                "Sliding pendulum"   ,"dae2/dae2.dem.gateway.sce"   ];
 
 subdemolist(:,2) = demopath + subdemolist(:,2);
+clear demopath;
\ No newline at end of file
index d0d271c..8897d97 100644 (file)
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2008 - INRIA
+// Copyright (C) 2010 - DIGITEO - Allan CORNET
 //
 // This file is released into the public domain
 
-funcprot(0);
+function demo_pend3d1()
+
+  function h = poly3d(x,y,z)
+    xpoly(x,y);
+    h = gce();
+    h.data(:,3) = z;
+  endfunction
+
+  m = 1;  // mass
+  g = 10; // gravity
+  l = 1;  // length
+
+  theta0 = 0.2;
+  phi0   = %pi/4;
+
+  x0=l*[sin(phi0)*cos(theta0);cos(phi0)*cos(theta0);sin(theta0)];
+
+
+  function c=ggpp(x,u,lambda)
+    c = 2*(u'*u+x'*(-2*lambda/m*x-[0;0;g]));
+  endfunction
+
+  // initial compatible point
+  u0      = [1;-1;0];
+  function  r=ff(l),r=ggpp(x0,u0,l);endfunction
+  lambda0 = fsolve(0,ff);
+  ud0     = -2*lambda0/m*x0-[0;0;g];
+  y0      = [x0;u0;lambda0];
+  yd0     = [u0;ud0;0];
+  t0      = 0;
+
+  //Observation dates for simulation
+  T       = t0:0.01:15;
+
+  //Slver tolerances
+  info = list([],0,[],[],[],0,0);
+  atol = [0.0001;0.0001;0.0001;0.001;0.001;0.001;1];
+  rtol = atol;
+
+  //index 1 DAE model
+  //-----------------
+  function [res,ires]=index1(t,y,ydot)
+    x        = y(1:3);
+    u        = y(4:6);
+    lambda   = y(7);
+    xp       = ydot(1:3);
+    up       = ydot(4:6);
+    lambdap  = ydot(7);
+    res(1:3) = xp-u;
+    res(4:6) = up+2*lambda/m*x+[0;0;g];
+    res(7)   = ggpp(x,u,lambda);
+    ires     = 0;
+  endfunction
+
+  y1   = dassl([y0,yd0],t0,T,rtol,atol,index1,info);
+  x1=y1(2:4,:);
+
+  //index 1 + stabilization  DAE model
+  //----------------------------------
+  alfa = 20;
+  Beta = 20;
+
+  function [res,ires]=index1s(t,y,ydot)
+    [res,ires]=index1(t,y,ydot)
+    x         = y(1:3);
+    u         = y(4:6);
+    res(7)    = res(7) + Beta*Beta*gg(x)+2*alfa*ggp(x,u);
+  endfunction
+
+  function c=gg(x),c= x'*x-l*l;endfunction
+  function c=ggp(x,u),c = 2*x'*u;endfunction
+
+  y1s  = dassl([y0,yd0],t0,T,rtol,atol,index1s,info);
+  x1s  = y1s(2:4,:);
+
+  //index 2  DAE model
+  function [res,ires]=index2(t,y,ydot)
+    x        = y(1:3);
+    u        = y(4:6);
+    lambda   = y(7);
+    xp       = ydot(1:3);
+    up       = ydot(4:6);
+    lambdap  = ydot(7);
+    res(1:3) = xp-u;
+    res(4:6) = up+2*lambda/m*x+[0;0;g];
+    res(7)   = ggp(x,u);
+    ires=0;
+  endfunction
+
+  y2 = dassl([y0,yd0],t0,T,rtol,atol,index2,info);
+  x2 = y2(2:4,:);
+
+  //disp([norm(x1(:,$),2) norm(x1s(:,$),2) norm(x2(:,$),2) ])
+
+  my_handle = scf(100001);
+  clf(my_handle,"reset");
+  demo_viewCode("pend3d1.dem.sce");
 
-function h=poly3d(x,y,z)
-  xpoly(x,y);h=gce();h.data(:,3)=z
-endfunction
-
-m = 1;  // mass
-g = 10; // gravity
-l = 1;  // length
-
-theta0 = 0.2;
-phi0   = %pi/4;
-
-x0=l*[sin(phi0)*cos(theta0);cos(phi0)*cos(theta0);sin(theta0)];
-
-
-function c=ggpp(x,u,lambda)
-  c = 2*(u'*u+x'*(-2*lambda/m*x-[0;0;g]));
-endfunction
+  drawlater()
+  title(_("spherical pendulum simulation"),"fontsize",3)
+  a                 = gca();
+  a.view            = '3d';
+  a.box             = 'on';
+  a.margins         = [0.1 0 0.2 0.1];
+  a.isoview         = 'on'
+  a.grid            =color('lightgray')*ones(1,3);
+  a.rotation_angles = [35 45];
+  a.axes_visible    = "on";
+  a.data_bounds     = [min(x1(1,:)),min(x1(2,:)),min(x1(3,:))
+             max(x1(1,:)),max(x1(2,:)),max(x1(3,:))];
+
+  p1=poly3d(x1(1,1),x1(2,1),x1(3,1));
+  p1s=poly3d(x1s(1,1),x1s(2,1),x1s(3,1));
+  p1s.foreground=color('red');
+  p2=poly3d(x2(1,1),x2(2,1),x2(3,1));
+  p2.foreground=color('blue');
+  l=legend(['index1','index1+stabilization','index2'])
+  drawnow();
+
+  step=10;
+  for k=1:step:(size(x1,2)-step)
+  
+    if ~is_handle_valid(my_handle) then
+      break;
+    end
+
+    if is_handle_valid(p1) then
+      p1.data = [p1.data
+        x1(:,k:(k+step-1))'];
+    end
+    
+    if is_handle_valid(p1s) then
+      p1s.data = [p1s.data
+        x1s(:,k:(k+step-1))'];
+    end
+    
+    if is_handle_valid(p2) then
+      p2.data = [p2.data
+         x2(:,k:(k+step-1))'];
+    end
+  end
 
-// initial compatible point
-u0      = [1;-1;0];
-function  r=ff(l),r=ggpp(x0,u0,l);endfunction
-lambda0 = fsolve(0,ff);
-ud0     = -2*lambda0/m*x0-[0;0;g];
-y0      = [x0;u0;lambda0];
-yd0     = [u0;ud0;0];
-t0      = 0;
-
-//Observation dates for simulation
-T       = t0:0.01:15;
-
-//Slver tolerances
-info = list([],0,[],[],[],0,0);
-atol = [0.0001;0.0001;0.0001;0.001;0.001;0.001;1];
-rtol = atol;
-
-//index 1 DAE model
-//-----------------
-function [res,ires]=index1(t,y,ydot)
-  x        = y(1:3);
-  u        = y(4:6);
-  lambda   = y(7);
-  xp       = ydot(1:3);
-  up       = ydot(4:6);
-  lambdap  = ydot(7);
-  res(1:3) = xp-u;
-  res(4:6) = up+2*lambda/m*x+[0;0;g];
-  res(7)   = ggpp(x,u,lambda);
-  ires     = 0;
 endfunction
 
-y1   = dassl([y0,yd0],t0,T,rtol,atol,index1,info);
-x1=y1(2:4,:);
-
-//index 1 + stabilization  DAE model
-//----------------------------------
-alfa = 20;
-Beta = 20;
+demo_pend3d1();
+clear demo_pend3d1; 
 
-function [res,ires]=index1s(t,y,ydot)
-  [res,ires]=index1(t,y,ydot)
-  x         = y(1:3);
-  u         = y(4:6);
-  res(7)    = res(7) + Beta*Beta*gg(x)+2*alfa*ggp(x,u);
-endfunction
-function c=gg(x),c= x'*x-l*l;endfunction
-function c=ggp(x,u),c = 2*x'*u;endfunction
-
-y1s  = dassl([y0,yd0],t0,T,rtol,atol,index1s,info);
-x1s  = y1s(2:4,:);
-
-//index 2  DAE model
-function [res,ires]=index2(t,y,ydot)
-       x        = y(1:3);
-       u        = y(4:6);
-       lambda   = y(7);
-       xp       = ydot(1:3);
-       up       = ydot(4:6);
-       lambdap  = ydot(7);
-       res(1:3) = xp-u;
-       res(4:6) = up+2*lambda/m*x+[0;0;g];
-       res(7)   = ggp(x,u);
-       ires=0;
-endfunction
-
-y2 = dassl([y0,yd0],t0,T,rtol,atol,index2,info);
-x2 = y2(2:4,:);
-
-disp([norm(x1(:,$),2) norm(x1s(:,$),2) norm(x2(:,$),2) ])
-
-my_handle = scf(100001);
-clf(my_handle,"reset");
-demo_viewCode("pend3d1.dem.sce");
-
-drawlater()
-title(_("spherical pendulum simulation"),"fontsize",3)
-a                 = gca();
-a.view            = '3d';
-a.box             = 'on';
-a.margins         = [0.1 0 0.2 0.1];
-a.isoview         = 'on'
-a.grid            =color('lightgray')*ones(1,3);
-a.rotation_angles = [35 45];
-a.axes_visible    = "on";
-a.data_bounds     = [min(x1(1,:)),min(x1(2,:)),min(x1(3,:))
-                    max(x1(1,:)),max(x1(2,:)),max(x1(3,:))];
-
-p1=poly3d(x1(1,1),x1(2,1),x1(3,1));
-p1s=poly3d(x1s(1,1),x1s(2,1),x1s(3,1));
-p1s.foreground=color('red');
-p2=poly3d(x2(1,1),x2(2,1),x2(3,1));
-p2.foreground=color('blue');
-l=legend(['index1','index1+stabilization','index2'])
-drawnow();
-
-step=10;
-for k=1:step:(size(x1,2)-step)
-  drawlater()
-  p1.data=[p1.data
-         x1(:,k:(k+step-1))'];
-  p1s.data=[p1s.data
-         x1s(:,k:(k+step-1))'];
-  p2.data=[p2.data
-          x2(:,k:(k+step-1))'];
-  drawnow()
-  
-end
 
-funcprot(1);
index dd203c5..f35f6e4 100644 (file)
@@ -9,3 +9,4 @@ subdemolist = ["parabola"          , "pendg1.dem.sce"   ; ..
                "Upside down camel" , "pendg2.dem.sce"  ]
 
 subdemolist(:,2) = demopath + subdemolist(:,2);
+clear demopath;
\ No newline at end of file
index ecfd51f..2ec146c 100644 (file)
 funcprot(0);
 
 function demo_sliding_pendulum()
-       
-       //
-       // Sliding pendulum
-       
-       //  demo_help  demo_sliding_pendulum
-       
-       //pendulum parameters
-       g = 10;
-       l = 1;
-       m = 1;
-       M = 1;
-       k = 0.5;
-       
-       //initial point
-       global omega;
-       omega = 3.3;
-       x0    = [1;1+cos(omega)/3;0]; 
-       u0    = [0;0;0];
-       y0    = [x0;u0;0];
-       ud0   = [0;-g;0]; 
-       yd0   = [u0;ud0;0];
-       
-       //set observation times
-       t0=0;
-       T=t0:0.05:20;
-       
-       //dassl parameters
-       info = list([],0,[],[],[],0,0);
-       atol = [0.0001;0.0001;0.0001;0.0001;0.0001;0.0001;0.001];
-       rtol = atol;
-       
-       // dae integration
-       sol=dassl([y0,yd0],t0,T,rtol,atol,pendg,info);
-       
-       //draw pendulum at its initial position
-       H = build_sliding_pendulum ()
-       draw_sliding_pendulum(H,y0(1:3))
-       
-       //visualization of the result
-       realtimeinit(0.05);realtime(0) 
-       for i=1:size(sol,2)
-               realtime(i)
-               draw_sliding_pendulum(H,sol(2:4,i))
-       end
+
+    //
+    // Sliding pendulum
+
+    //  demo_help  demo_sliding_pendulum
+
+    //pendulum parameters
+    g = 10;
+    l = 1;
+    m = 1;
+    M = 1;
+    k = 0.5;
+
+    //initial point
+    global omega;
+    omega = 3.3;
+    x0    = [1;1+cos(omega)/3;0];
+    u0    = [0;0;0];
+    y0    = [x0;u0;0];
+    ud0   = [0;-g;0];
+    yd0   = [u0;ud0;0];
+
+    //set observation times
+    t0=0;
+    T=t0:0.05:20;
+
+    //dassl parameters
+    info = list([],0,[],[],[],0,0);
+    atol = [0.0001;0.0001;0.0001;0.0001;0.0001;0.0001;0.001];
+    rtol = atol;
+
+    // dae integration
+    sol=dassl([y0,yd0],t0,T,rtol,atol,pendg,info);
+
+    //draw pendulum at its initial position
+    H = build_sliding_pendulum ()
+    draw_sliding_pendulum(H,y0(1:3))
+
+    //visualization of the result
+    realtimeinit(0.05);realtime(0)
+    for i=1:size(sol,2)
+        realtime(i)
+        if is_handle_valid(H) then
+          draw_sliding_pendulum(H,sol(2:4,i))
+        else
+          break;
+        end
+    end
 
 endfunction
 
 
 function [res,ires]=pendg(t,y,ydot)
-       
-       //DAE external for sliding pendulum
-       
-       x=y(1:3);
-       u=y(4:6);
-       lambda=y(7);
-       xp=ydot(1:3);
-       up=ydot(4:6);
-       
-       res=[xp-u;
-               (M+m)*up(1)     + m*l*(cos(x(3))*up(3)-sin(x(3))*u(3)^2) + lambda*fx(x(1),x(2)) + k*u(1);
-               (M+m)*(up(2)+g) + m*l*(sin(x(3))*up(3)+cos(x(3))*u(3)^2) + lambda*fy(x(1),x(2)) + k*u(2);
-                                               m*l*(cos(x(3))*up(1)+sin(x(3))*up(2))  + m*l^2*up(3) + m*g*sin(x(3));
-               -(fx(x(1),x(2))*u(1)+fy(x(1),x(2))*u(2))];
-       ires=0;
+
+    //DAE external for sliding pendulum
+
+    x=y(1:3);
+    u=y(4:6);
+    lambda=y(7);
+    xp=ydot(1:3);
+    up=ydot(4:6);
+
+    res=[xp-u;
+        (M+m)*up(1)     + m*l*(cos(x(3))*up(3)-sin(x(3))*u(3)^2) + lambda*fx(x(1),x(2)) + k*u(1);
+        (M+m)*(up(2)+g) + m*l*(sin(x(3))*up(3)+cos(x(3))*u(3)^2) + lambda*fy(x(1),x(2)) + k*u(2);
+                        m*l*(cos(x(3))*up(1)+sin(x(3))*up(2))  + m*l^2*up(3) + m*g*sin(x(3));
+        -(fx(x(1),x(2))*u(1)+fy(x(1),x(2))*u(2))];
+    ires=0;
 endfunction
 
 function res=fx(x,y)
   global omega;
-       res=-2*x+omega*sin(omega*x)/3;
+    res=-2*x+omega*sin(omega*x)/3;
 endfunction
 
 function res=fy(x,y)
-       res=1;
+    res=1;
 endfunction
 
 
 function  H=build_sliding_pendulum ()
-       
-       global omega;
-       
-       //build the sliding pendulum figure and graphic objects, 
-       //return the handle on moving parts
-       
-       f = scf(100001);
-       clf(f,"reset");
-
-       a=gca();
-       f.pixmap='on';
-       drawlater()
-       f.axes_size = [610,676];
-       xmin=-1.5;
-       xmax=1.5;
-       ymin=-1.1;
-       ymax=2.35
-       a.data_bounds=[xmin ymin;xmax ymax]
-       a.isoview = "on";
-       //the framework
-       xrect(xmin,ymax,xmax-xmin,ymax-ymin)
-       //the curve
-       vx=[xmin:0.01:xmax]'; vy=vx.*vx+cos(omega*vx)/3;
-       xpoly(vx,vy,"lines")
-       c=gce();c.foreground=5;
-       //the pendulum segment
-       x=0; y=0; teta=0;
-       xp=x+l*sin(teta); yp=y-l*cos(teta);
-       r=0.05 // the bullet half diameter
-       xp1=x+(l-r)*sin(teta); yp1=y-(l-r)*cos(teta);
-       xpoly([x;xp1],[y;yp1],"lines")
-       p=gce();p.thickness=2;
-       //the pendulum bullet
-       xfarc(xp-r,yp+r,2*r,2*r,0,360*64)
-       b=gce()
-       H=glue([p,b]) //return the handle on segment and bullet
+
+    global omega;
+
+    //build the sliding pendulum figure and graphic objects,
+    //return the handle on moving parts
+
+    f = scf(100001);
+    clf(f,"reset");
+
+    a=gca();
+    f.pixmap='on';
+    drawlater()
+    f.axes_size = [610,676];
+    xmin=-1.5;
+    xmax=1.5;
+    ymin=-1.1;
+    ymax=2.35
+    a.data_bounds=[xmin ymin;xmax ymax]
+    a.isoview = "on";
+    //the framework
+    xrect(xmin,ymax,xmax-xmin,ymax-ymin)
+    //the curve
+    vx=[xmin:0.01:xmax]'; vy=vx.*vx+cos(omega*vx)/3;
+    xpoly(vx,vy,"lines")
+    c=gce();c.foreground=5;
+    //the pendulum segment
+    x=0; y=0; teta=0;
+    xp=x+l*sin(teta); yp=y-l*cos(teta);
+    r=0.05 // the bullet half diameter
+    xp1=x+(l-r)*sin(teta); yp1=y-(l-r)*cos(teta);
+    xpoly([x;xp1],[y;yp1],"lines")
+    p=gce();p.thickness=2;
+    //the pendulum bullet
+    xfarc(xp-r,yp+r,2*r,2*r,0,360*64)
+    b=gce()
+    H=glue([p,b]) //return the handle on segment and bullet
 endfunction
 
 
 
 function  draw_sliding_pendulum (H,state)
-//draw the pendulum in a given state  
-  x=state(1); y=state(2); teta=state(3); 
+  //draw the pendulum in a given state
+  x = state(1);
+  y = state(2);
+  teta = state(3);
+  
   // bullet half diameter
-  b = H.children(1);r=b.data(3)/2
+  b = H.children(1);
+  r = b.data(3)/2;
 
   xp=x+l*sin(teta); yp=y-l*cos(teta);
   xp1=x+(l-r)*sin(teta); yp1=y-(l-r)*cos(teta);
diff --git a/scilab/modules/differential_equations/demos/dae/dae2/demo_sliding_pendulum_fr.htm b/scilab/modules/differential_equations/demos/dae/dae2/demo_sliding_pendulum_fr.htm
deleted file mode 100644 (file)
index a5e7045..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-<html>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-<title>demo_sliding_pendulum</title>
-</head>
-<body bgcolor="#FFFFFF">
-<center><h1><font color="blue">Modélisation et simulation d'un pendule glissant </font></h1></center>
-
-
-<h2>
-
-
-<li>- Modélisation Lagrangienne d'un système méchanique</li>
-<li>- Calcul formel et génération de code</li>
-<li>- Simulation d'équations algébro-differentielles </li>
-<li>- Compilation et link incrémental "à la volée"</li>
-<li>- Visualisation</li>
-
-<center>
-<p></p>
-<p></p>
-
-
-<p>par </p>
-<p></p>
-<p></p>
-
-<p>Claude Gomez</p>
-<p>INRIA</p>
-
-</center>
-</h2>
-
-</body>
-</html>
index cc9d464..ffa3b0c 100644 (file)
@@ -8,86 +8,86 @@
 funcprot(0);
 
 function [res,ires]=pendg(t,y,ydot)
-       x          = y(1:3);
-       u          = y(4:6);
-       lambda     = y(7);
-       xp         = ydot(1:3);
-       up         = ydot(4:6);
-       res(1:3)   = xp-u;
-       res(4)     = (M+m)*up(1)+m*l*cos(x(3))*up(3)-m*l*sin(x(3))*u(3)^2+lambda*fx(x(1),x(2))+k*u(1);
-       res(5)     = (M+m)*up(2)+m*l*sin(x(3))*up(3)+m*l*cos(x(3))*u(3)^2+(M+m)*g+lambda*fy(x(1),x(2))+k*u(2);
-       res(6)     = m*l*cos(x(3))*up(1)+m*l*sin(x(3))*up(2)+m*l^2*up(3)+m*g*sin(x(3));
-       res(7)     = -(fx(x(1),x(2))*u(1)+fy(x(1),x(2))*u(2));
-       ires       = 0;
+    x          = y(1:3);
+    u          = y(4:6);
+    lambda     = y(7);
+    xp         = ydot(1:3);
+    up         = ydot(4:6);
+    res(1:3)   = xp-u;
+    res(4)     = (M+m)*up(1)+m*l*cos(x(3))*up(3)-m*l*sin(x(3))*u(3)^2+lambda*fx(x(1),x(2))+k*u(1);
+    res(5)     = (M+m)*up(2)+m*l*sin(x(3))*up(3)+m*l*cos(x(3))*u(3)^2+(M+m)*g+lambda*fy(x(1),x(2))+k*u(2);
+    res(6)     = m*l*cos(x(3))*up(1)+m*l*sin(x(3))*up(2)+m*l^2*up(3)+m*g*sin(x(3));
+    res(7)     = -(fx(x(1),x(2))*u(1)+fy(x(1),x(2))*u(2));
+    ires       = 0;
 endfunction
 
 
 
 function  H=build_sliding_pendulum ()
-       
-       //build the sliding pendulum figure and graphic objects, 
-       //return the handle on moving parts
-       
-       f = scf(100001);
-       clf(f,"reset");
-       
-       f             = gcf();
-       f.pixmap      = "on";
-       a             = gca();
-       drawlater();
-       f.axes_size = [610,676] ;
-       
-       xmin = -1.5;
-       xmax =  1.5;
-       ymin = -1.1;
-       ymax =  2.25;
-       a.data_bounds=[xmin ymin;xmax ymax]
-       a.isoview = "on";
-       
-       //the framework
-       xrect(xmin,ymax,xmax-xmin,ymax-ymin)
-       
-       //the curve
-       vx=[xmin:0.1:xmax]';
-       vy=vx^2;
-       xpoly(vx,vy,"lines")
-       c=gce();
-       c.foreground=5;
-       
-       //the pendulum segment
-       x           = 0;
-       y           = 0;
-       teta        = 0;
-       xp          = x+l*sin(teta); yp=y-l*cos(teta);
-       r           = 0.05 // the bullet half diameter
-       xp1         = x+(l-r)*sin(teta);
-       yp1         = y-(l-r)*cos(teta);
-       xpoly([x;xp1],[y;yp1],"lines")
-       p           = gce();
-       p.thickness = 2;
-       //the pendulum bullet
-       xfarc(xp-r,yp+r,2*r,2*r,0,360*64)
-       b           = gce()
-       H           = glue([p,b]) //return the handle on segment and bullet
+
+    //build the sliding pendulum figure and graphic objects,
+    //return the handle on moving parts
+
+    f = scf(100001);
+    clf(f,"reset");
+
+    f             = gcf();
+    f.pixmap      = "on";
+    a             = gca();
+    drawlater();
+    f.axes_size = [610,676] ;
+
+    xmin = -1.5;
+    xmax =  1.5;
+    ymin = -1.1;
+    ymax =  2.25;
+    a.data_bounds=[xmin ymin;xmax ymax]
+    a.isoview = "on";
+
+    //the framework
+    xrect(xmin,ymax,xmax-xmin,ymax-ymin)
+
+    //the curve
+    vx=[xmin:0.1:xmax]';
+    vy=vx^2;
+    xpoly(vx,vy,"lines")
+    c=gce();
+    c.foreground=5;
+
+    //the pendulum segment
+    x           = 0;
+    y           = 0;
+    teta        = 0;
+    xp          = x+l*sin(teta); yp=y-l*cos(teta);
+    r           = 0.05 // the bullet half diameter
+    xp1         = x+(l-r)*sin(teta);
+    yp1         = y-(l-r)*cos(teta);
+    xpoly([x;xp1],[y;yp1],"lines")
+    p           = gce();
+    p.thickness = 2;
+    //the pendulum bullet
+    xfarc(xp-r,yp+r,2*r,2*r,0,360*64)
+    b           = gce()
+    H           = glue([p,b]) //return the handle on segment and bullet
 endfunction
 
 
 function  draw_sliding_pendulum (H,state)
-       //draw the pendulum in a given state  
-       x=state(1); y=state(2); teta=state(3); 
-       // bullet half diameter
-       b = H.children(1);r=b.data(3)/2
-       
-       xp=x+l*sin(teta); yp=y-l*cos(teta);
-       xp1=x+(l-r)*sin(teta); yp1=y-(l-r)*cos(teta);
-       drawlater()
-       p = H.children(2);p.data=[x, y; xp1, yp1];
-       b = H.children(1); b.data=[xp-r,yp+r,2*r,2*r,0,360*64];
-       drawnow();
-       show_pixmap()
-       a=gca();
-       a.title.text='sliding pendulum, parabola';
-       a.title.font_size=3;
+    //draw the pendulum in a given state
+    x=state(1); y=state(2); teta=state(3);
+    // bullet half diameter
+    b = H.children(1);r=b.data(3)/2
+
+    xp=x+l*sin(teta); yp=y-l*cos(teta);
+    xp1=x+(l-r)*sin(teta); yp1=y-(l-r)*cos(teta);
+    drawlater()
+    p = H.children(2);p.data=[x, y; xp1, yp1];
+    b = H.children(1); b.data=[xp-r,yp+r,2*r,2*r,0,360*64];
+    drawnow();
+    show_pixmap()
+    a=gca();
+    a.title.text='sliding pendulum, parabola';
+    a.title.font_size=3;
 endfunction
 
 funcprot(1);
index f9eef83..223abaf 100644 (file)
@@ -7,35 +7,44 @@
 // Sliding pendulum, curve #1
 //
 
-exec(SCI+"/modules/differential_equations/demos/dae/dae2/pendg.sci");
-exec(SCI+"/modules/differential_equations/demos/dae/dae2/pendc1.sci");
-
-g    = 10;
-l    = 1;
-m    = 1;
-M    = 1;
-k    = 0.5;
-x0   = [1;1;0];
-u0   = [0;0;0];
-y0   = [x0;u0;0];
-ud0  = [0;-g;0];
-yd0  = [u0;ud0;0];
-
-t0   = 0;
-T    = t0:0.05:20;
-
-info = list([],0,[],[],[],0,0);
-atol = [0.0001;0.0001;0.0001;0.0001;0.0001;0.0001;0.001];
-rtol = atol;
-
-sol  = dassl([y0,yd0],t0,T,rtol,atol,pendg,info);
-
-H    = build_sliding_pendulum ()
-draw_sliding_pendulum(H,y0(1:3))
-
-//visualization of the result
-realtimeinit(0.05);realtime(0) 
-for i=1:size(sol,2)
-  realtime(i)
-  draw_sliding_pendulum(H,sol(2:4,i))
-end
+function demo_pendg1()
+
+  exec(SCI+"/modules/differential_equations/demos/dae/dae2/pendg.sci");
+  exec(SCI+"/modules/differential_equations/demos/dae/dae2/pendc1.sci");
+
+  g    = 10;
+  l    = 1;
+  m    = 1;
+  M    = 1;
+  k    = 0.5;
+  x0   = [1;1;0];
+  u0   = [0;0;0];
+  y0   = [x0;u0;0];
+  ud0  = [0;-g;0];
+  yd0  = [u0;ud0;0];
+
+  t0   = 0;
+  T    = t0:0.05:20;
+
+  info = list([],0,[],[],[],0,0);
+  atol = [0.0001;0.0001;0.0001;0.0001;0.0001;0.0001;0.001];
+  rtol = atol;
+
+  sol  = dassl([y0,yd0],t0,T,rtol,atol,pendg,info);
+
+  H    = build_sliding_pendulum ()
+  draw_sliding_pendulum(H,y0(1:3))
+
+  //visualization of the result
+  realtimeinit(0.05);realtime(0) 
+  for i=1:size(sol,2)
+    realtime(i);
+    if is_handle_valid(H) then
+      draw_sliding_pendulum(H,sol(2:4,i))
+    end
+  end
+
+endfunction
+
+demo_pendg1();
+clear demo_pendg1;
\ No newline at end of file
index bd0e5e0..f11948d 100644 (file)
@@ -7,8 +7,15 @@
 // Sliding pendulum, curve #2
 //
 
-exec(SCI+"/modules/differential_equations/demos/dae/dae2/pendg.sci");
-exec(SCI+"/modules/differential_equations/demos/dae/dae2/pendc1.sci");
-exec(SCI+"/modules/differential_equations/demos/dae/dae2/demo_sliding_pendulum.sci");
+function demo_pendg2()
 
-demo_sliding_pendulum()
+  exec(SCI+"/modules/differential_equations/demos/dae/dae2/pendg.sci");
+  exec(SCI+"/modules/differential_equations/demos/dae/dae2/pendc1.sci");
+  exec(SCI+"/modules/differential_equations/demos/dae/dae2/demo_sliding_pendulum.sci");
+
+  demo_sliding_pendulum()
+  
+endfunction 
+
+demo_pendg2();
+clear demo_pendg2;
\ No newline at end of file
index c4d8b45..a176b51 100644 (file)
 // ====================================
 
 function exeblackhole()
-  
+
 //initial point
   g_r = 1.1;
   g_t = 41;
-  
+
   //initial speed
   g_V    = 1.65;
   g_Vdir = 165;
-  
+
   // Figure parameters
   // =========================================================================
-  
+
   surface_frame_w = 600;     // surface frame width
   surface_frame_h = 600;     // surface frame height
-  
+
   control_frame_w = 600;
   control_frame_h = 200;
-  
+
   margin_x     = 15;      // Horizontal margin between each elements
   margin_y     = 15;      // Vertical margin between each elements
-  
+
   axes_figure_w = 2*margin_x + max(surface_frame_w,control_frame_w);
   axes_figure_h = 3*margin_y + surface_frame_h + control_frame_h;
-  
+
   // Figure creation
   // =========================================================================
-  
+
   my_figure_handle = scf(100001);
   clf(my_figure_handle,"reset");
-  
+
   my_figure_handle.background      = -2;
   my_figure_handle.figure_position = [0 0];
   my_figure_handle.axes_size       = [axes_figure_w axes_figure_h];
   my_figure_handle.figure_name     = gettext("Blackhole");
-  
-   
+
+
   //reserve The upper part of the graphic windows for the 3d view of the scene
   curAxe=gca();
   curAxe.axes_bounds = [0,0,1,3/4];
   draw_blackhole();
   draw_initial_point(g_r,g_t,g_V,g_Vdir,%T);
-  
+
   //Create the controls in the window bottom
   // =========================================================================
 
   blackhole_create_gui()
-  
+
   //Set control and graphics initial values
   // =========================================================================
   change_r(g_r)
   change_theta(g_t)
   change_speed(g_V)
   change_dir(g_Vdir)
-  
+
 endfunction
 
 // draw_surface
 // ====================================
 
 function draw_blackhole()
-  
+
   r    = 1;
   orig = [0 0 0];
   xx   = -1.85:0.1:1.85;
   yy   = (-1.85:0.1:1.85)';
   zt   = sqrt((ones(yy)*(xx^2)+(yy^2)*ones(xx)));
   zz   = -1*ones(zt)./zt;
-  
+
   my_handle          = scf(100001);
-  
+
   my_axe             = newaxes();
   my_axe.axes_bounds = [0,0,1,3/4];
-  
+
   my_handle.immediate_drawing = "off";
   mesh(xx,yy,zz);
   e            = gce();
-  e.color_mode = 0; 
+  e.color_mode = 0;
   e.foreground=color("blue");
   my_handle.immediate_drawing = "on";
 endfunction
@@ -104,37 +104,37 @@ function draw_initial_point(g_r,g_t,g_V,g_Vdir,create)
   dy1 = g_V*sin(g_Vdir*%pi/180);
   my_figure_handle = scf(100001);
   my_figure_handle.immediate_drawing = "off";
-       
+
   if create then
     //create the graphical object used to visualize the trajectory
-    xpoly(0,0) 
+    xpoly(0,0)
     traj_handle                        =gce();
-    traj_handle.thickness              = 2; 
+    traj_handle.thickness              = 2;
     traj_handle.foreground             = 5;
     //create the graphical object used to visualize the initial speed
-    xpoly(0,0) 
+    xpoly(0,0)
     speed_handle                       =  gce();
     speed_handle.thickness             =  1;
     speed_handle.foreground            =  5;
     speed_handle.polyline_style        =  4;
     speed_handle.arrow_size_factor     =  2;
     //create the graphical objects used to visualize the initial position
-    param3d([x-r,x+r],[y,y],[z,z]);  
-    e1                                 = gce(); 
-    e1.thickness                       = 1; 
+    param3d([x-r,x+r],[y,y],[z,z]);
+    e1                                 = gce();
+    e1.thickness                       = 1;
     e1.foreground                      = 5;
-    param3d([x,x],[y-r,y+r],[z,z]);  
-    e2                                 = gce(); 
-    e2.thickness                       = 1; 
+    param3d([x,x],[y-r,y+r],[z,z]);
+    e2                                 = gce();
+    e2.thickness                       = 1;
     e2.foreground                      = 5;
-    param3d([x,x],[y,y],[z-r,z+r]);  
-    e3                                 = gce(); 
-    e3.thickness                       = 1; 
+    param3d([x,x],[y,y],[z-r,z+r]);
+    e3                                 = gce();
+    e3.thickness                       = 1;
     e3.foreground                      = 5;
     glue([traj_handle speed_handle e1 e2 e3])
   else
     curAxe = gca();
-    initial=curAxe.children(1).children
+    initial = curAxe.children(1).children
     initial(1).data = [x,y,z-r;x,y,z+r];
     initial(2).data = [x,y-r,z;x,y+r,z];
     initial(3).data = [x-r,y,z;x+r,y,z];
@@ -142,7 +142,7 @@ function draw_initial_point(g_r,g_t,g_V,g_Vdir,create)
   z1= -1.0./sqrt((x+dx1)^2+(y+dy1)^2)+r;
   initial(4).data = [x,y,z;x+dx1,y+dy1,z1];
 
-  my_figure_handle.immediate_drawing = "on";   
+  my_figure_handle.immediate_drawing = "on";
 endfunction
 
 // =============================================================================
@@ -151,237 +151,237 @@ endfunction
 
 function blackhole_create_gui()
   //initial values
-       
-       g_t     = 0;
-       g_r     = 0;
-       g_speed = 0;
-       g_Vdir   = 0;
-       
-       my_figure_handle = scf(100001);
-       
-       axes_size_figure = my_figure_handle.axes_size;
-       axes_figure_w    = axes_size_figure(1);
-       axes_figure_h    = axes_size_figure(2);
-       
-       frame_x      = 25;
-       frame_y      = 200;
-       
-       slider_height   = 15;
-       slider_width    = 140;
-       value_width     = 30;
-       unit_width      = 30;
-       text_width      = 50;
-       y_margin        = 5;
+
+    g_t     = 0;
+    g_r     = 0;
+    g_speed = 0;
+    g_Vdir   = 0;
+
+    my_figure_handle = scf(100001);
+
+    axes_size_figure = my_figure_handle.axes_size;
+    axes_figure_w    = axes_size_figure(1);
+    axes_figure_h    = axes_size_figure(2);
+
+    frame_x      = 25;
+    frame_y      = 200;
+
+    slider_height   = 15;
+    slider_width    = 140;
+    value_width     = 30;
+    unit_width      = 30;
+    text_width      = 50;
+    y_margin        = 5;
         x_margin        = 10;
-       title_width     =  text_width + slider_width + value_width + unit_width +3*x_margin
-       
-       x_text         = frame_x
-       x_slider        = x_text + text_width + x_margin;
-       x_value         = x_slider + slider_width+x_margin;
-       x_unit          = x_value  + value_width+x_margin;
-       
-       y               = frame_y-40;
-       
-       // Title position
-       // =========================================================================
-       
-       title_r = uicontrol(my_figure_handle                             , ...
-               "position"            , [x_text y title_width slider_height+y_margin]   , ...
-               "Style"               , "text"                                   , ...
-               "String"              , "Starting point"                         , ...
-               "BackgroundColor"     , [1 1 1]                                  , ...
-               "Fontsize"            , 16                                       , ...
-               "horizontalalignment" , "center"                                 , ...
-               "tag"                 , "title_r"                            );
-       
-       // Slider "r"
-       // =========================================================================
-       y = y - (slider_height+y_margin)
-       text_r = uicontrol(my_figure_handle                              , ...
-               "position"          , [x_text y text_width slider_height]    , ...
-               "Style"             , "text"                                 , ...
-               "String"            , "r"                                    , ...
-               "BackgroundColor"   , [1 1 1]                                , ...
-               "tag"               , "text_r"                           );
-       
-       slider_r = uicontrol(my_figure_handle                            , ...
-               "position"          , [x_slider y slider_width slider_height], ...
-               "Style"             , "slider"                               , ...
-               "Value"             , g_r                                 , ...
-               "Min"               , 0                                      , ...
-               "Max"               , 100                                      , ...
-               "callback"          , "change_r()"                           , ...
-               "tag"               , "slider_r"                         );
-       
-       value_r = uicontrol(my_figure_handle                             , ...
-               "position"          , [x_value  y value_width slider_height] , ...
-               "Style"             , "text"                                 , ...
-               "String"            , string(g_r)                            , ...
-               "BackgroundColor"   , [1 1 1]                                , ...
-               "tag"               , "value_r"                          );
-       
-       unite_r = uicontrol(my_figure_handle                             , ...
-               "position"          , [x_unit y unit_width slider_height]    , ...
-               "Style"             , "text"                                 , ...
-               "String"            , "(m)"                                  , ...
-               "BackgroundColor"   , [1 1 1]                                , ...
-               "tag"               , "unite_r"                          );
-       
-       // Slider theta
-       // =========================================================================
-       y = y - (slider_height+y_margin)
-       text_theta = uicontrol(my_figure_handle                          , ...
-               "position"       , [x_text y text_width slider_height]       , ...
-               "Style"          , "text"                                    , ...
-               "String"         , "theta"                                   , ...
-               "BackgroundColor", [1 1 1]                                   , ...
-               "tag"            , "text_theta"                              );
-       
-       slider_theta = uicontrol(my_figure_handle                        , ...
-               "position"  , [x_slider y slider_width slider_height]        , ...
-               "Style"     , "slider"                                       , ...
-               "Min"       , 0                                              , ...
-               "Max"       , 100                                            , ...
-               "Value"     , g_t                                            , ...
-               "callback"  , "change_theta()"                                   , ...
-               "tag"       , "slider_theta"                                 );
-       
-       value_theta = uicontrol(my_figure_handle                         , ...
-               "position"        , [x_value  y value_width  slider_height]  , ...
-               "Style"           , "text"                                   , ...
-               "String"          , string(g_t)                              , ...
-               "BackgroundColor" , [1 1 1]                                  , ...
-               "tag"             , "value_theta"                            );
-       
-       unite_theta = uicontrol(my_figure_handle                         , ...
-               "position"        , [x_unit y unit_width slider_height]      , ...
-               "Style"           , "text"                                   , ...
-               "String"          , "(deg)"                                  , ...
-               "BackgroundColor" , [1 1 1]                                  , ...
-               "tag"             , "unite_theta"                            );
-       //---------------------------------------------------------------------------
-       //second column 
-       x_text          = frame_x + title_width + 3*x_margin
-       x_slider        = x_text + text_width + x_margin;
-       x_value         = x_slider + slider_width+x_margin;
-       x_unit          = x_value  + value_width+x_margin;
-       
-       y               = frame_y-40;
-
-       // Title speed
-       // =========================================================================
-       
-       title_speed = uicontrol(my_figure_handle                             , ...
-               "position"            , [x_text y title_width slider_height+y_margin],...
-               "Style"               , "text"                                   , ...
-               "String"              , "Initial speed"                          , ...
-               "BackgroundColor"     , [1 1 1]                                  , ...
-               "Fontsize"            , 16                                       , ...
-               "horizontalalignment" , "center"                                 , ...
-               "tag"                 , "title_speed"                            );
-       
-       // Slider speed
-       // =========================================================================
-       y = y - (slider_height+y_margin)
-       text_speed = uicontrol(my_figure_handle                          , ...
-               "position"          , [x_text y text_width slider_height]    , ...
-               "Style"             , "text"                                 , ...
-               "String"            , "speed"                                , ...
-               "BackgroundColor"   , [1 1 1]                                , ...
-               "tag"               , "text_speed"                           );
-       
-       slider_speed = uicontrol(my_figure_handle                        , ...
-               "position"          , [x_slider y slider_width slider_height], ...
-               "Style"             , "slider"                               , ...
-               "Value"             , g_speed                                , ...
-               "Min"               , 0                                      , ...
-               "Max"               , 100                                      , ...
-               "callback"          , "change_speed()"                       , ...
-               "tag"               , "slider_speed"                         );
-       
-       value_speed = uicontrol(my_figure_handle                         , ...
-               "position"          , [x_value  y value_width slider_height] , ...
-               "Style"             , "text"                                 , ...
-               "String"            , string(g_speed)                        , ...
-               "BackgroundColor"   , [1 1 1]                                , ...
-               "tag"               , "value_speed"                          );
-       
-       unite_speed = uicontrol(my_figure_handle                         , ...
-               "position"          , [x_unit y unit_width slider_height]    , ...
-               "Style"             , "text"                                 , ...
-               "String"            , "(m/s)"                                  , ...
-               "BackgroundColor"   , [1 1 1]                                , ...
-               "tag"               , "unite_speed"                          );
-       
-       // Slider direction
-       // =========================================================================
-       y = y - (slider_height+y_margin)
-       text_dir = uicontrol(my_figure_handle                            , ...
-               "position"       , [x_text y text_width slider_height]       , ...
-               "Style"          , "text"                                    , ...
-               "String"         , "direction"                                   , ...
-               "BackgroundColor", [1 1 1]                                   , ...
-               "tag"            , "text_dir"                              );
-       
-       slider_dir = uicontrol(my_figure_handle                          , ...
-               "position"  , [x_slider y slider_width slider_height]        , ...
-               "Style"     , "slider"                                       , ...
-               "Min"       , 0                                              , ...
-               "Max"       , 100                                            , ...
-               "Value"     , g_Vdir                                           , ...
-               "callback"  , "change_dir()"                                   , ...
-               "tag"       , "slider_dir"                                 );
-       
-       value_dir = uicontrol(my_figure_handle                           , ...
-               "position"        , [x_value  y value_width  slider_height]  , ...
-               "Style"           , "text"                                   , ...
-               "String"          , string(g_Vdir)                              , ...
-               "BackgroundColor" , [1 1 1]                                  , ...
-               "tag"             , "value_dir"                            );
-       
-       unite_dir = uicontrol(my_figure_handle                           , ...
-               "position"        , [x_unit y unit_width slider_height]      , ...
-               "Style"           , "text"                                   , ...
-               "String"          , "(deg)"                                  , ...
-               "BackgroundColor" , [1 1 1]                                  , ...
-               "tag"             , "unite_dir"                            );
-       // Buttons
-       // =========================================================================
-       y = y - (slider_height+5*y_margin)
-       btn_width=100;
-       btn_margin=50;
-       btn_height=20;
-       x=frame_x+80
-       start_button = uicontrol(my_figure_handle                                   , ...
-               "Position"             , [x y btn_width btn_height]                 , ...
-               "Style"                , "pushbutton"                               , ...
-               "String"               , "Start"                                    , ...
-               "Fontsize"             , 14                                         , ...
-               "BackgroundColor"      , [1 1 1]                                    , ...
-               "callback"             , "start_simu()"                             , ...
-               "tag"                  , "start_button"                             );
-       
-       x=x+btn_width+btn_margin
-       stop_button = uicontrol(my_figure_handle                                    , ...
-               "Position"               , [x y btn_width btn_height]               , ...
-               "Style"                  , "pushbutton"                             , ...
-               "String"                 , "Stop"                                   , ...
-               "Fontsize"               , 14                                       , ...
-               "BackgroundColor"        , [1 1 1]                                  , ...
-               "callback"               , "stop_simu"                              , ...
-               "tag"                    , "stop_button"                            );
-
-       x=x+btn_width+btn_margin
-       clear_button = uicontrol(my_figure_handle                                   , ...
-               "Position"               , [x y btn_width btn_height]               , ...
-               "Style"                  , "pushbutton"                             , ...
-               "String"                 , "Clear"                                  , ...
-               "Fontsize"               , 14                                       , ...
-               "BackgroundColor"        , [1 1 1]                                  , ...
-               "callback"               , "clear_simu"                             , ...
-               "tag"                    , "clear_button"                           );
-       
-       return
+    title_width     =  text_width + slider_width + value_width + unit_width +3*x_margin
+
+    x_text         = frame_x
+    x_slider        = x_text + text_width + x_margin;
+    x_value         = x_slider + slider_width+x_margin;
+    x_unit          = x_value  + value_width+x_margin;
+
+    y               = frame_y-40;
+
+    // Title position
+    // =========================================================================
+
+    title_r = uicontrol(my_figure_handle                             , ...
+        "position"            , [x_text y title_width slider_height+y_margin]   , ...
+        "Style"               , "text"                                   , ...
+        "String"              , "Starting point"                         , ...
+        "BackgroundColor"     , [1 1 1]                                  , ...
+        "Fontsize"            , 16                                       , ...
+        "horizontalalignment" , "center"                                 , ...
+        "tag"                 , "title_r"                            );
+
+    // Slider "r"
+    // =========================================================================
+    y = y - (slider_height+y_margin)
+    text_r = uicontrol(my_figure_handle                              , ...
+        "position"          , [x_text y text_width slider_height]    , ...
+        "Style"             , "text"                                 , ...
+        "String"            , "r"                                    , ...
+        "BackgroundColor"   , [1 1 1]                                , ...
+        "tag"               , "text_r"                           );
+
+    slider_r = uicontrol(my_figure_handle                            , ...
+        "position"          , [x_slider y slider_width slider_height], ...
+        "Style"             , "slider"                               , ...
+        "Value"             , g_r                                 , ...
+        "Min"               , 0                                      , ...
+        "Max"               , 100                                      , ...
+        "callback"          , "change_r()"                           , ...
+        "tag"               , "slider_r"                         );
+
+    value_r = uicontrol(my_figure_handle                             , ...
+        "position"          , [x_value  y value_width slider_height] , ...
+        "Style"             , "text"                                 , ...
+        "String"            , string(g_r)                            , ...
+        "BackgroundColor"   , [1 1 1]                                , ...
+        "tag"               , "value_r"                          );
+
+    unite_r = uicontrol(my_figure_handle                             , ...
+        "position"          , [x_unit y unit_width slider_height]    , ...
+        "Style"             , "text"                                 , ...
+        "String"            , "(m)"                                  , ...
+        "BackgroundColor"   , [1 1 1]                                , ...
+        "tag"               , "unite_r"                          );
+
+    // Slider theta
+    // =========================================================================
+    y = y - (slider_height+y_margin)
+    text_theta = uicontrol(my_figure_handle                          , ...
+        "position"       , [x_text y text_width slider_height]       , ...
+        "Style"          , "text"                                    , ...
+        "String"         , "theta"                                   , ...
+        "BackgroundColor", [1 1 1]                                   , ...
+        "tag"            , "text_theta"                              );
+
+    slider_theta = uicontrol(my_figure_handle                        , ...
+        "position"  , [x_slider y slider_width slider_height]        , ...
+        "Style"     , "slider"                                       , ...
+        "Min"       , 0                                              , ...
+        "Max"       , 100                                            , ...
+        "Value"     , g_t                                            , ...
+        "callback"  , "change_theta()"                                   , ...
+        "tag"       , "slider_theta"                                 );
+
+    value_theta = uicontrol(my_figure_handle                         , ...
+        "position"        , [x_value  y value_width  slider_height]  , ...
+        "Style"           , "text"                                   , ...
+        "String"          , string(g_t)                              , ...
+        "BackgroundColor" , [1 1 1]                                  , ...
+        "tag"             , "value_theta"                            );
+
+    unite_theta = uicontrol(my_figure_handle                         , ...
+        "position"        , [x_unit y unit_width slider_height]      , ...
+        "Style"           , "text"                                   , ...
+        "String"          , "(deg)"                                  , ...
+        "BackgroundColor" , [1 1 1]                                  , ...
+        "tag"             , "unite_theta"                            );
+    //---------------------------------------------------------------------------
+    //second column
+    x_text          = frame_x + title_width + 3*x_margin
+    x_slider        = x_text + text_width + x_margin;
+    x_value         = x_slider + slider_width+x_margin;
+    x_unit          = x_value  + value_width+x_margin;
+
+    y               = frame_y-40;
+
+    // Title speed
+    // =========================================================================
+
+    title_speed = uicontrol(my_figure_handle                             , ...
+        "position"            , [x_text y title_width slider_height+y_margin],...
+        "Style"               , "text"                                   , ...
+        "String"              , "Initial speed"                          , ...
+        "BackgroundColor"     , [1 1 1]                                  , ...
+        "Fontsize"            , 16                                       , ...
+        "horizontalalignment" , "center"                                 , ...
+        "tag"                 , "title_speed"                            );
+
+    // Slider speed
+    // =========================================================================
+    y = y - (slider_height+y_margin)
+    text_speed = uicontrol(my_figure_handle                          , ...
+        "position"          , [x_text y text_width slider_height]    , ...
+        "Style"             , "text"                                 , ...
+        "String"            , "speed"                                , ...
+        "BackgroundColor"   , [1 1 1]                                , ...
+        "tag"               , "text_speed"                           );
+
+    slider_speed = uicontrol(my_figure_handle                        , ...
+        "position"          , [x_slider y slider_width slider_height], ...
+        "Style"             , "slider"                               , ...
+        "Value"             , g_speed                                , ...
+        "Min"               , 0                                      , ...
+        "Max"               , 100                                      , ...
+        "callback"          , "change_speed()"                       , ...
+        "tag"               , "slider_speed"                         );
+
+    value_speed = uicontrol(my_figure_handle                         , ...
+        "position"          , [x_value  y value_width slider_height] , ...
+        "Style"             , "text"                                 , ...
+        "String"            , string(g_speed)                        , ...
+        "BackgroundColor"   , [1 1 1]                                , ...
+        "tag"               , "value_speed"                          );
+
+    unite_speed = uicontrol(my_figure_handle                         , ...
+        "position"          , [x_unit y unit_width slider_height]    , ...
+        "Style"             , "text"                                 , ...
+        "String"            , "(m/s)"                                  , ...
+        "BackgroundColor"   , [1 1 1]                                , ...
+        "tag"               , "unite_speed"                          );
+
+    // Slider direction
+    // =========================================================================
+    y = y - (slider_height+y_margin)
+    text_dir = uicontrol(my_figure_handle                            , ...
+        "position"       , [x_text y text_width slider_height]       , ...
+        "Style"          , "text"                                    , ...
+        "String"         , "direction"                                   , ...
+        "BackgroundColor", [1 1 1]                                   , ...
+        "tag"            , "text_dir"                              );
+
+    slider_dir = uicontrol(my_figure_handle                          , ...
+        "position"  , [x_slider y slider_width slider_height]        , ...
+        "Style"     , "slider"                                       , ...
+        "Min"       , 0                                              , ...
+        "Max"       , 100                                            , ...
+        "Value"     , g_Vdir                                           , ...
+        "callback"  , "change_dir()"                                   , ...
+        "tag"       , "slider_dir"                                 );
+
+    value_dir = uicontrol(my_figure_handle                           , ...
+        "position"        , [x_value  y value_width  slider_height]  , ...
+        "Style"           , "text"                                   , ...
+        "String"          , string(g_Vdir)                              , ...
+        "BackgroundColor" , [1 1 1]                                  , ...
+        "tag"             , "value_dir"                            );
+
+    unite_dir = uicontrol(my_figure_handle                           , ...
+        "position"        , [x_unit y unit_width slider_height]      , ...
+        "Style"           , "text"                                   , ...
+        "String"          , "(deg)"                                  , ...
+        "BackgroundColor" , [1 1 1]                                  , ...
+        "tag"             , "unite_dir"                            );
+    // Buttons
+    // =========================================================================
+    y = y - (slider_height+5*y_margin)
+    btn_width=100;
+    btn_margin=50;
+    btn_height=20;
+    x=frame_x+80
+    start_button = uicontrol(my_figure_handle                                   , ...
+        "Position"             , [x y btn_width btn_height]                 , ...
+        "Style"                , "pushbutton"                               , ...
+        "String"               , "Start"                                    , ...
+        "Fontsize"             , 14                                         , ...
+        "BackgroundColor"      , [1 1 1]                                    , ...
+        "callback"             , "start_simu()"                             , ...
+        "tag"                  , "start_button"                             );
+
+    x=x+btn_width+btn_margin
+    stop_button = uicontrol(my_figure_handle                                    , ...
+        "Position"               , [x y btn_width btn_height]               , ...
+        "Style"                  , "pushbutton"                             , ...
+        "String"                 , "Stop"                                   , ...
+        "Fontsize"               , 14                                       , ...
+        "BackgroundColor"        , [1 1 1]                                  , ...
+        "callback"               , "stop_simu"                              , ...
+        "tag"                    , "stop_button"                            );
+
+    x=x+btn_width+btn_margin
+    clear_button = uicontrol(my_figure_handle                                   , ...
+        "Position"               , [x y btn_width btn_height]               , ...
+        "Style"                  , "pushbutton"                             , ...
+        "String"                 , "Clear"                                  , ...
+        "Fontsize"               , 14                                       , ...
+        "BackgroundColor"        , [1 1 1]                                  , ...
+        "callback"               , "clear_simu"                             , ...
+        "tag"                    , "clear_button"                           );
+
+    return
 endfunction
 
 // =============================================================================
@@ -389,14 +389,14 @@ endfunction
 // =============================================================================
 
 function change_r(r)
-//r slider callback 
+//r slider callback
   // r is in [0.08 2]
   slider_r     = findobj("tag", "slider_r");
   slider_theta = findobj("tag", "slider_theta");
   slider_speed = findobj("tag", "slider_speed");
   slider_dir   = findobj("tag", "slider_dir");
   slider_r     = findobj("tag", "slider_r");
+
   value_r       = findobj("tag", "value_r");
   if argn(2)==1 then
     slider_r.Value=(r-0.007)/(2-0.08)*100;
@@ -406,20 +406,20 @@ function change_r(r)
   end
   value_r.String=msprintf("%.3f",r)
   draw_initial_point(0.007+slider_r.Value*(2-0.08)/100,slider_theta.value*360/100,..
-                    slider_speed.Value*3/100,slider_dir.value*360/100,%F);
-  
+             slider_speed.Value*3/100,slider_dir.value*360/100,%F);
+
 endfunction
 
 
 function change_theta(theta)
-//theta slider callback  
+//theta slider callback
 //theta is in [0 360]
   slider_r     = findobj("tag", "slider_r");
   slider_theta = findobj("tag", "slider_theta");
   slider_speed = findobj("tag", "slider_speed");
   slider_dir   = findobj("tag", "slider_dir");
   slider_r     = findobj("tag", "slider_r");
+
   value_theta   = findobj("tag", "value_theta");
   if argn(2)==1 then
     slider_theta.Value=(theta)*100/360;
@@ -429,12 +429,12 @@ function change_theta(theta)
   end
   value_theta.String=msprintf("%.0f",theta)
   draw_initial_point(0.007+slider_r.Value*(2-0.08)/100,slider_theta.value*360/100,..
-                    slider_speed.Value*3/100,slider_dir.value*360/100,%F);
+             slider_speed.Value*3/100,slider_dir.value*360/100,%F);
 
 endfunction
 
 function change_speed(speed)
-//speed slider callback  
+//speed slider callback
 //speed is in [0 3]
   slider_r     = findobj("tag", "slider_r");
   slider_theta = findobj("tag", "slider_theta");
@@ -450,11 +450,11 @@ function change_speed(speed)
   end
   value_speed.String=msprintf("%.0f",speed)
   draw_initial_point(0.007+slider_r.Value*(2-0.08)/100,slider_theta.value*360/100,..
-                    slider_speed.Value*3/100,slider_dir.value*360/100,%F);
+             slider_speed.Value*3/100,slider_dir.value*360/100,%F);
 endfunction
 
 function change_dir(dir)
-//direction slider callback  
+//direction slider callback
 //dir is in [0 360]
   slider_r      = findobj("tag", "slider_r");
   slider_theta  = findobj("tag", "slider_theta");
@@ -469,11 +469,11 @@ function change_dir(dir)
   end
   value_dir.String=msprintf("%.0f",dir)
   draw_initial_point(0.007+slider_r.Value*(2-0.08)/100,slider_theta.value*360/100,..
-                    slider_speed.Value*3/100,slider_dir.value*360/100,%F);
+             slider_speed.Value*3/100,slider_dir.value*360/100,%F);
 endfunction
 
 function start_simu()
-//start button callback
+  //start button callback
   my_figure_handle = scf(100001);
   fin=my_figure_handle.user_data
   my_figure_handle.user_data=%f
@@ -481,32 +481,44 @@ function start_simu()
   slider_theta = findobj("tag", "slider_theta");
   slider_speed = findobj("tag", "slider_speed");
   slider_dir   = findobj("tag", "slider_dir");
-  t     = 0:0.02:15; 
+  t     = 0:0.02:15;
   Y = calculate_traj(0.007+slider_r.Value*(2-0.08)/100,slider_theta.value*360/100, ...
-                    slider_speed.Value*3/100,slider_dir.value*360/100,t)
+             slider_speed.Value*3/100,slider_dir.value*360/100,t)
   x = Y(1,:)
   y = Y(3,:)
   r = 0.1; //bias to have the curve above the surface
   z = -1.0./sqrt(x^2+y^2)+r;
-   curAxe = gca();
-  traj_handle=curAxe.children(1).children(5);
-  traj_handle.data=[x(1),y(1),z(1)];
+  curAxe = gca();
+  traj_handle = curAxe.children(1).children(5);
+  traj_handle.data = [x(1),y(1),z(1)];
+  
   for k=2:size(x,'*')
-    if execstr('fin=my_figure_handle.user_data','errcatch')<>0|fin then break,end
-    traj_handle.data=[traj_handle.data;[x(k),y(k),z(k)]];
+    if is_handle_valid(my_figure_handle) then
+      if execstr('fin=my_figure_handle.user_data','errcatch')<>0|fin then break,end
+      if is_handle_valid(traj_handle) then
+        traj_handle.data = [traj_handle.data ; [x(k),y(k),z(k)]];
+      else
+        break;
+      end
+    else
+      break;
+    end
+  end
+  
+  if is_handle_valid(my_figure_handle) then
+    my_figure_handle.user_data=%t;
   end
-  my_figure_handle.user_data=%t;
 endfunction
 
 function stop_simu()
-//stop button callback
+  //stop button callback
   my_figure_handle = scf(100001);
   fin   = %T;
   my_figure_handle.user_data=fin
 endfunction
 
 function clear_simu()
-//clear button callback
+  //clear button callback
   my_figure_handle = scf(100001);
   fin=my_figure_handle.user_data
   if fin then
index 4ccd7f0..b46bc42 100644 (file)
@@ -18,15 +18,15 @@ endfunction
 
 
 function [p,q,r,s,t]=SlantedCylinder(x,y)
-       
-       a = -tan(slope/180*%pi);
-       z = sqrt(1-x^2)
-       p = x/z;
-       q = a //pente
-       r = 1/(z^3)
-       s = 0
-       t = 0
-       
+
+    a = -tan(slope/180*%pi);
+    z = sqrt(1-x^2)
+    p = x/z;
+    q = a //pente
+    r = 1/(z^3)
+    s = 0
+    t = 0
+
 endfunction
 
 
@@ -43,21 +43,21 @@ function r=cyllim(t,y),
      y(3)
      y(3)-14]
 endfunction
-       
+
 Y0(1) = g_x;//x
 Y0(2) = g_V*cos(g_Vdir*%pi/180);//v_x
 Y0(3) = g_y;//y
 Y0(4) = g_V*sin(g_Vdir*%pi/180);//v_y
 Y     = ode('root',Y0,t(1),t,1d-10,1.D-10,list(traj,SlantedCylinder),4,cyllim);//traj d'ecoulement
-       
+
 endfunction
 
 // draw_bille
 // =============================================================================
 
 function draw_bille(Y)
-       g_tx = Y(1,:)';
-       g_ty = Y(3,:)';
-       g_tz = -sqrt(1-g_tx^2-g_ty^2);
+    g_tx = Y(1,:)';
+    g_ty = Y(3,:)';
+    g_tz = -sqrt(1-g_tx^2-g_ty^2);
 endfunction
 
index 876a46d..8fbcaf4 100644 (file)
 // Step 1, set up the gradient
 // =============================================================================
 function execylinder()
-       gravity        = 9.81
-       g_pente  = 14;
-       
-       g_x      = 0.6;
-       g_y      = 0.7;
-       
-       g_V      = 1;
-       g_Vdir   = 180;
-       
-       g_alpha  = 35;
-       g_theta  = 45;
-       
-       // Figure parameters
-       // =========================================================================
-       
-       surface_frame_w = 600;     // surface frame width
-       surface_frame_h = 600;     // surface frame height
-       
-       control_frame_w = 600;
-       control_frame_h = 200;
-       
-       margin_x     = 15;      // Horizontal margin between each elements
-       margin_y     = 15;      // Vertical margin between each elements
-       
-       axes_figure_w = 2*margin_x + max(surface_frame_w,control_frame_w);
-       axes_figure_h = 3*margin_y + surface_frame_h + control_frame_h;
-       
-       // Figure creation
-       // =========================================================================
-       
-       my_figure_handle = scf(100001);
-       clf(my_figure_handle,"reset");
-       my_figure_handle.immediate_drawing = "off";
-       my_figure_handle.background      = -2;
-       my_figure_handle.figure_position = [0 0];
-       my_figure_handle.axes_size       = [axes_figure_w axes_figure_h];
-       my_figure_handle.figure_name     = gettext("Cylinder");
-
-       my_axe                           = gca()
-       my_axe.axes_bounds               = [0,0,1,3/4];
-       my_axe.tight_limits              = "on";
-       
-       draw_cylinder(g_pente,%T);
-       cylinder_create_gui()
-       change_x(g_x)
-       change_y(g_y)
-       change_speed(g_V)
-       change_dir(g_Vdir)
-       
-       draw_initial_point(g_x,g_y,g_V,g_Vdir,g_pente,%T)
-
-       my_figure_handle.immediate_drawing = "on";
+    gravity        = 9.81
+    g_pente  = 14;
+
+    g_x      = 0.6;
+    g_y      = 0.7;
+
+    g_V      = 1;
+    g_Vdir   = 180;
+
+    g_alpha  = 35;
+    g_theta  = 45;
+
+    // Figure parameters
+    // =========================================================================
+
+    surface_frame_w = 600;     // surface frame width
+    surface_frame_h = 600;     // surface frame height
+
+    control_frame_w = 600;
+    control_frame_h = 200;
+
+    margin_x     = 15;      // Horizontal margin between each elements
+    margin_y     = 15;      // Vertical margin between each elements
+
+    axes_figure_w = 2*margin_x + max(surface_frame_w,control_frame_w);
+    axes_figure_h = 3*margin_y + surface_frame_h + control_frame_h;
+
+    // Figure creation
+    // =========================================================================
+
+    my_figure_handle = scf(100001);
+    clf(my_figure_handle,"reset");
+    my_figure_handle.immediate_drawing = "off";
+    my_figure_handle.background      = -2;
+    my_figure_handle.figure_position = [0 0];
+    my_figure_handle.axes_size       = [axes_figure_w axes_figure_h];
+    my_figure_handle.figure_name     = gettext("Cylinder");
+
+    my_axe                           = gca()
+    my_axe.axes_bounds               = [0,0,1,3/4];
+    my_axe.tight_limits              = "on";
+
+    draw_cylinder(g_pente,%T);
+    cylinder_create_gui()
+    change_x(g_x)
+    change_y(g_y)
+    change_speed(g_V)
+    change_dir(g_Vdir)
+
+    draw_initial_point(g_x,g_y,g_V,g_Vdir,g_pente,%T)
+
+    my_figure_handle.immediate_drawing = "on";
 endfunction
 
 // draw_cylinder
@@ -74,7 +74,7 @@ function draw_cylinder(g_pente,orig)
   a  = -tan(g_pente/180*%pi);
   xx = -1:0.1:1;
   yy = (0:1:14)';
-  
+
   if orig then
     Z                       = -sqrt(1-ones(yy)*(xx^2))+a*yy*ones(xx);
     plot3d(xx,yy,Z');
@@ -98,32 +98,32 @@ function draw_initial_point(x,y,g_V,g_Vdir,slope,create)
   dy1 = g_V*sin(g_Vdir*%pi/180);
   my_figure_handle = scf(100001);
   my_figure_handle.immediate_drawing = "off";
-       
+
   if create then
     //create the graphical object used to visualize the trajectory
-    xpoly(0,0) 
+    xpoly(0,0)
     traj_handle                        =gce();
-    traj_handle.thickness              = 2; 
+    traj_handle.thickness              = 2;
     traj_handle.foreground             = 5;
     //create the graphical object used to visualize the initial speed
-    xpoly(0,0) 
+    xpoly(0,0)
     speed_handle                       =  gce();
     speed_handle.thickness             =  1;
     speed_handle.foreground            =  5;
     speed_handle.polyline_style        =  4;
     speed_handle.arrow_size_factor     =  2;
     //create the graphical objects used to visualize the initial position
-    param3d([x-r,x+r],[y,y],[z,z]);  
-    e1                                 = gce(); 
-    e1.thickness                       = 1; 
+    param3d([x-r,x+r],[y,y],[z,z]);
+    e1                                 = gce();
+    e1.thickness                       = 1;
     e1.foreground                      = 5;
-    param3d([x,x],[y-r,y+r],[z,z]);  
-    e2                                 = gce(); 
-    e2.thickness                       = 1; 
+    param3d([x,x],[y-r,y+r],[z,z]);
+    e2                                 = gce();
+    e2.thickness                       = 1;
     e2.foreground                      = 5;
-    param3d([x,x],[y,y],[z-r,z+r]);  
-    e3                                 = gce(); 
-    e3.thickness                       = 1; 
+    param3d([x,x],[y,y],[z-r,z+r]);
+    e3                                 = gce();
+    e3.thickness                       = 1;
     e3.foreground                      = 5;
     glue([traj_handle speed_handle e1 e2 e3])
   else
@@ -136,7 +136,7 @@ function draw_initial_point(x,y,g_V,g_Vdir,slope,create)
   z1=-sqrt(1-(x+dx1)^2)+a*(y+dy1)+r;
   initial(4).data = [x,y,z;x+dx1,y+dy1,z1];
 
-  my_figure_handle.immediate_drawing = "on";   
+  my_figure_handle.immediate_drawing = "on";
 endfunction
 
 // =============================================================================
@@ -151,16 +151,16 @@ function cylinder_create_gui()
     g_y     = 0;
     g_speed = 0;
     g_Vdir  = 0;
-       
+
     my_figure_handle = scf(100001);
-       
+
     axes_size_figure = my_figure_handle.axes_size;
     axes_figure_w    = axes_size_figure(1);
     axes_figure_h    = axes_size_figure(2);
-       
+
     frame_x      = 25;
     frame_y      = 200;
-       
+
     slider_height   = 15;
     slider_width    = 140;
     value_width     = 30;
@@ -169,233 +169,233 @@ function cylinder_create_gui()
     y_margin        = 5;
     x_margin        = 10;
     title_width     =  (text_width + slider_width + value_width + unit_width +3*x_margin)
-       
+
     x_text         = frame_x
     x_slider        = x_text + text_width + x_margin;
     x_value         = x_slider + slider_width+x_margin;
     x_unit          = x_value  + value_width+x_margin;
-       
+
     y               = frame_y-40;
-       
+
     // Title position
     // =========================================================================
-    
+
     title = uicontrol(my_figure_handle                             , ...
-                     "position"            , [x_text y 2*title_width slider_height+y_margin]   , ...
-                     "Style"               , "text"                                   , ...
-                     "String"              , "Set parameters"                         , ...
-                     "BackgroundColor"     , [1 1 1]                                  , ...
-                     "Fontsize"            , 16                                       , ...
-                     "horizontalalignment" , "center"                                 , ...
-                     "tag"                 , "physics" );
-    
+              "position"            , [x_text y 2*title_width slider_height+y_margin]   , ...
+              "Style"               , "text"                                   , ...
+              "String"              , "Set parameters"                         , ...
+              "BackgroundColor"     , [1 1 1]                                  , ...
+              "Fontsize"            , 16                                       , ...
+              "horizontalalignment" , "center"                                 , ...
+              "tag"                 , "physics" );
+
     // Slider "gravity"
     // =========================================================================
     y  = y - (slider_height+y_margin)
     y0 = y
     text_g = uicontrol(my_figure_handle                              , ...
-                      "position"          , [x_text y text_width slider_height]    , ...
-                      "Style"             , "text"                                 , ...
-                      "String"            , "gravity"                                    , ...
-                      "BackgroundColor"   , [1 1 1]                                , ...
-                      "tag"               , "text_g"                           );
-    
+               "position"          , [x_text y text_width slider_height]    , ...
+               "Style"             , "text"                                 , ...
+               "String"            , "gravity"                                    , ...
+               "BackgroundColor"   , [1 1 1]                                , ...
+               "tag"               , "text_g"                           );
+
     slider_g = uicontrol(my_figure_handle                            , ...
-                        "position"          , [x_slider y slider_width slider_height], ...
-                        "Style"             , "slider"                               , ...
-                        "Value"             , gravity                                 , ...
-                        "Min"               , 0                                      , ...
-                        "Max"               , 100                                      , ...
-                        "callback"          , "change_gravity()"                           , ...
-                        "tag"               , "slider_gravity"                         );
-    
+             "position"          , [x_slider y slider_width slider_height], ...
+             "Style"             , "slider"                               , ...
+             "Value"             , gravity                                 , ...
+             "Min"               , 0                                      , ...
+             "Max"               , 100                                      , ...
+             "callback"          , "change_gravity()"                           , ...
+             "tag"               , "slider_gravity"                         );
+
     value_g = uicontrol(my_figure_handle                             , ...
-                       "position"          , [x_value  y value_width slider_height] , ...
-                       "Style"             , "text"                                 , ...
-                       "String"            , string(gravity)                            , ...
-                       "BackgroundColor"   , [1 1 1]                                , ...
-                       "tag"               , "value_g"                          );
-    
+            "position"          , [x_value  y value_width slider_height] , ...
+            "Style"             , "text"                                 , ...
+            "String"            , string(gravity)                            , ...
+            "BackgroundColor"   , [1 1 1]                                , ...
+            "tag"               , "value_g"                          );
+
     unite_g = uicontrol(my_figure_handle                             , ...
-                       "position"          , [x_unit y unit_width slider_height]    , ...
-                       "Style"             , "text"                                 , ...
-                       "String"            , "(m/s^-2)"                                  , ...
-                       "BackgroundColor"   , [1 1 1]                                , ...
-                       "tag"               , "unite_g"                          );
-    
+            "position"          , [x_unit y unit_width slider_height]    , ...
+            "Style"             , "text"                                 , ...
+            "String"            , "(m/s^-2)"                                  , ...
+            "BackgroundColor"   , [1 1 1]                                , ...
+            "tag"               , "unite_g"                          );
+
     // Slider x
     // =========================================================================
     y = y - (slider_height+y_margin)
     text_x = uicontrol(my_figure_handle                          , ...
-                      "position"       , [x_text y text_width slider_height]       , ...
-                      "Style"          , "text"                                    , ...
-                      "String"         , "x"                                   , ...
-                      "BackgroundColor", [1 1 1]                                   , ...
-                      "tag"            , "text_x"                              );
+               "position"       , [x_text y text_width slider_height]       , ...
+               "Style"          , "text"                                    , ...
+               "String"         , "x"                                   , ...
+               "BackgroundColor", [1 1 1]                                   , ...
+               "tag"            , "text_x"                              );
     slider_x = uicontrol(my_figure_handle                        , ...
-                        "position"  , [x_slider y slider_width slider_height]        , ...
-                        "Style"     , "slider"                                       , ...
-                        "Min"       , 0                                              , ...
-                        "Max"       , 100                                            , ...
-                        "Value"     , g_x                                            , ...
-                        "callback"  , "change_x()"                                   , ...
-                        "tag"       , "slider_x"                                 );
-    
+             "position"  , [x_slider y slider_width slider_height]        , ...
+             "Style"     , "slider"                                       , ...
+             "Min"       , 0                                              , ...
+             "Max"       , 100                                            , ...
+             "Value"     , g_x                                            , ...
+             "callback"  , "change_x()"                                   , ...
+             "tag"       , "slider_x"                                 );
+
     value_x = uicontrol(my_figure_handle                         , ...
-                       "position"        , [x_value  y value_width  slider_height]  , ...
-                       "Style"           , "text"                                   , ...
-                       "String"          , string(g_x)                              , ...
-                       "BackgroundColor" , [1 1 1]                                  , ...
-                       "tag"             , "value_x"                            );
-    
+            "position"        , [x_value  y value_width  slider_height]  , ...
+            "Style"           , "text"                                   , ...
+            "String"          , string(g_x)                              , ...
+            "BackgroundColor" , [1 1 1]                                  , ...
+            "tag"             , "value_x"                            );
+
     unite_x = uicontrol(my_figure_handle                         , ...
-                       "position"        , [x_unit y unit_width slider_height]      , ...
-                       "Style"           , "text"                                   , ...
-                       "String"          , "(m)"                                  , ...
-                       "BackgroundColor" , [1 1 1]                                  , ...
-                       "tag"             , "unite_x" ...
-                       );
+            "position"        , [x_unit y unit_width slider_height]      , ...
+            "Style"           , "text"                                   , ...
+            "String"          , "(m)"                                  , ...
+            "BackgroundColor" , [1 1 1]                                  , ...
+            "tag"             , "unite_x" ...
+            );
     //Slider speed
     // =========================================================================
     y = y - (slider_height+y_margin)
     text_speed = uicontrol(my_figure_handle                          , ...
-                          "position"          , [x_text y text_width slider_height]    , ...
-                          "Style"             , "text"                                 , ...
-                          "String"            , "speed"                                , ...
-                          "BackgroundColor"   , [1 1 1]                                , ...
-                          "tag"               , "text_speed"                           );
-    
+               "position"          , [x_text y text_width slider_height]    , ...
+               "Style"             , "text"                                 , ...
+               "String"            , "speed"                                , ...
+               "BackgroundColor"   , [1 1 1]                                , ...
+               "tag"               , "text_speed"                           );
+
     slider_speed = uicontrol(my_figure_handle                        , ...
-                            "position"          , [x_slider y slider_width slider_height], ...
-                            "Style"             , "slider"                               , ...
-                            "Value"             , g_speed                                , ...
-                            "Min"               , 0                                      , ...
-                            "Max"               , 100                                      , ...
-                            "callback"          , "change_speed()"                       , ...
-                            "tag"               , "slider_speed"                         );
-    
+                 "position"          , [x_slider y slider_width slider_height], ...
+                 "Style"             , "slider"                               , ...
+                 "Value"             , g_speed                                , ...
+                 "Min"               , 0                                      , ...
+                 "Max"               , 100                                      , ...
+                 "callback"          , "change_speed()"                       , ...
+                 "tag"               , "slider_speed"                         );
+
     value_speed = uicontrol(my_figure_handle                         , ...
-                           "position"          , [x_value  y value_width slider_height] , ...
-                           "Style"             , "text"                                 , ...
-                           "String"            , string(g_speed)                        , ...
-                           "BackgroundColor"   , [1 1 1]                                , ...
-                           "tag"               , "value_speed"                          );
-    
+                "position"          , [x_value  y value_width slider_height] , ...
+                "Style"             , "text"                                 , ...
+                "String"            , string(g_speed)                        , ...
+                "BackgroundColor"   , [1 1 1]                                , ...
+                "tag"               , "value_speed"                          );
+
     unite_speed = uicontrol(my_figure_handle                         , ...
-                           "position"          , [x_unit y unit_width slider_height]    , ...
-                           "Style"             , "text"                                 , ...
-                           "String"            , "(m/s)"                                  , ...
-                           "BackgroundColor"   , [1 1 1]                                , ...
-                           "tag"               , "unite_speed"                          );
-    
-    
-    
+                "position"          , [x_unit y unit_width slider_height]    , ...
+                "Style"             , "text"                                 , ...
+                "String"            , "(m/s)"                                  , ...
+                "BackgroundColor"   , [1 1 1]                                , ...
+                "tag"               , "unite_speed"                          );
+
+
+
     //---------------------------------------------------------------------------
-    //second column 
+    //second column
     x_text          = frame_x + title_width + 3*x_margin
     x_slider        = x_text + text_width + x_margin;
     x_value         = x_slider + slider_width+x_margin;
     x_unit          = x_value  + value_width+x_margin;
-    
+
     y               = y0
 
     // Slider slope
     // =========================================================================
-    
+
     text_slope = uicontrol(my_figure_handle                          , ...
-                          "position"       , [x_text y text_width slider_height]       , ...
-                          "Style"          , "text"                                    , ...
-                          "String"         , "slope"                                   , ...
-                          "BackgroundColor", [1 1 1]                                   , ...
-                          "tag"            , "text_slope"                              );
-    
+               "position"       , [x_text y text_width slider_height]       , ...
+               "Style"          , "text"                                    , ...
+               "String"         , "slope"                                   , ...
+               "BackgroundColor", [1 1 1]                                   , ...
+               "tag"            , "text_slope"                              );
+
     slider_slope = uicontrol(my_figure_handle                        , ...
-                            "position"  , [x_slider y slider_width slider_height]        , ...
-                            "Style"     , "slider"                                       , ...
-                            "Min"       , 0                                              , ...
-                            "Max"       , 100                                            , ...
-                            "Value"     , g_pente                                            , ...
-                            "callback"  , "change_slope()"                                   , ...
-                            "tag"       , "slider_slope"                                 );
-    
+                 "position"  , [x_slider y slider_width slider_height]        , ...
+                 "Style"     , "slider"                                       , ...
+                 "Min"       , 0                                              , ...
+                 "Max"       , 100                                            , ...
+                 "Value"     , g_pente                                            , ...
+                 "callback"  , "change_slope()"                                   , ...
+                 "tag"       , "slider_slope"                                 );
+
     value_slope = uicontrol(my_figure_handle                         , ...
-                           "position"        , [x_value  y value_width  slider_height]  , ...
-                           "Style"           , "text"                                   , ...
-                           "String"          , string(g_pente)                              , ...
-                           "BackgroundColor" , [1 1 1]                                  , ...
-                           "tag"             , "value_slope"                            );
-    
+                "position"        , [x_value  y value_width  slider_height]  , ...
+                "Style"           , "text"                                   , ...
+                "String"          , string(g_pente)                              , ...
+                "BackgroundColor" , [1 1 1]                                  , ...
+                "tag"             , "value_slope"                            );
+
     unite_slope = uicontrol(my_figure_handle                         , ...
-                           "position"        , [x_unit y unit_width slider_height]      , ...
-                           "Style"           , "text"                                   , ...
-                           "String"          , "(deg)"                                  , ...
-                           "BackgroundColor" , [1 1 1]                                  , ...
-                           "tag"             , "unite_slope" ...
-                           );
+                "position"        , [x_unit y unit_width slider_height]      , ...
+                "Style"           , "text"                                   , ...
+                "String"          , "(deg)"                                  , ...
+                "BackgroundColor" , [1 1 1]                                  , ...
+                "tag"             , "unite_slope" ...
+                );
     // Slider y
     // =========================================================================
     y = y - (slider_height+y_margin)
     text_y = uicontrol(my_figure_handle                          , ...
-                      "position"       , [x_text y text_width slider_height]       , ...
-                      "Style"          , "text"                                    , ...
-                      "String"         , "y"                                   , ...
-                      "BackgroundColor", [1 1 1]                                   , ...
-                      "tag"            , "text_y"                              );
+               "position"       , [x_text y text_width slider_height]       , ...
+               "Style"          , "text"                                    , ...
+               "String"         , "y"                                   , ...
+               "BackgroundColor", [1 1 1]                                   , ...
+               "tag"            , "text_y"                              );
     slider_y = uicontrol(my_figure_handle                        , ...
-                        "position"  , [x_slider y slider_width slider_height]        , ...
-                        "Style"     , "slider"                                       , ...
-                        "Min"       , 0                                              , ...
-                        "Max"       , 100                                            , ...
-                        "Value"     , g_y                                            , ...
-                        "callback"  , "change_y()"                                   , ...
-                        "tag"       , "slider_y"                                 );
-    
+             "position"  , [x_slider y slider_width slider_height]        , ...
+             "Style"     , "slider"                                       , ...
+             "Min"       , 0                                              , ...
+             "Max"       , 100                                            , ...
+             "Value"     , g_y                                            , ...
+             "callback"  , "change_y()"                                   , ...
+             "tag"       , "slider_y"                                 );
+
     value_y = uicontrol(my_figure_handle                         , ...
-                       "position"        , [x_value  y value_width  slider_height]  , ...
-                       "Style"           , "text"                                   , ...
-                       "String"          , string(g_y)                              , ...
-                       "BackgroundColor" , [1 1 1]                                  , ...
-                       "tag"             , "value_y"                            );
-    
+            "position"        , [x_value  y value_width  slider_height]  , ...
+            "Style"           , "text"                                   , ...
+            "String"          , string(g_y)                              , ...
+            "BackgroundColor" , [1 1 1]                                  , ...
+            "tag"             , "value_y"                            );
+
     unite_y = uicontrol(my_figure_handle                         , ...
-                       "position"        , [x_unit y unit_width slider_height]      , ...
-                       "Style"           , "text"                                   , ...
-                       "String"          , "(m)"                                  , ...
-                       "BackgroundColor" , [1 1 1]                                  , ...
-                       "tag"             , "unite_y" ...
-                       );
+            "position"        , [x_unit y unit_width slider_height]      , ...
+            "Style"           , "text"                                   , ...
+            "String"          , "(m)"                                  , ...
+            "BackgroundColor" , [1 1 1]                                  , ...
+            "tag"             , "unite_y" ...
+            );
     // Slider direction
     // =========================================================================
     y = y - (slider_height+y_margin)
     text_dir = uicontrol(my_figure_handle                            , ...
-                        "position"       , [x_text y text_width slider_height]       , ...
-                        "Style"          , "text"                                    , ...
-                        "String"         , "direction"                                   , ...
-                        "BackgroundColor", [1 1 1]                                   , ...
-                        "tag"            , "text_dir"                              );
-    
+             "position"       , [x_text y text_width slider_height]       , ...
+             "Style"          , "text"                                    , ...
+             "String"         , "direction"                                   , ...
+             "BackgroundColor", [1 1 1]                                   , ...
+             "tag"            , "text_dir"                              );
+
     slider_dir = uicontrol(my_figure_handle                          , ...
-                          "position"  , [x_slider y slider_width slider_height]        , ...
-                          "Style"     , "slider"                                       , ...
-                          "Min"       , 0                                              , ...
-                          "Max"       , 100                                            , ...
-                          "Value"     , g_Vdir                                           , ...
-                          "callback"  , "change_dir()"                                   , ...
-                          "tag"       , "slider_dir"                                 );
-    
+               "position"  , [x_slider y slider_width slider_height]        , ...
+               "Style"     , "slider"                                       , ...
+               "Min"       , 0                                              , ...
+               "Max"       , 100                                            , ...
+               "Value"     , g_Vdir                                           , ...
+               "callback"  , "change_dir()"                                   , ...
+               "tag"       , "slider_dir"                                 );
+
     value_dir = uicontrol(my_figure_handle                           , ...
-                         "position"        , [x_value  y value_width  slider_height]  , ...
-                         "Style"           , "text"                                   , ...
-                         "String"          , string(g_Vdir)                              , ...
-                         "BackgroundColor" , [1 1 1]                                  , ...
-                         "tag"             , "value_dir"                            );
-    
+              "position"        , [x_value  y value_width  slider_height]  , ...
+              "Style"           , "text"                                   , ...
+              "String"          , string(g_Vdir)                              , ...
+              "BackgroundColor" , [1 1 1]                                  , ...
+              "tag"             , "value_dir"                            );
+
     unite_dir = uicontrol(my_figure_handle                           , ...
-                         "position"        , [x_unit y unit_width slider_height]      , ...
-                         "Style"           , "text"                                   , ...
-                         "String"          , "(deg)"                                  , ...
-                         "BackgroundColor" , [1 1 1]                                  , ...
-                         "tag"             , "unite_dir"                            );
+              "position"        , [x_unit y unit_width slider_height]      , ...
+              "Style"           , "text"                                   , ...
+              "String"          , "(deg)"                                  , ...
+              "BackgroundColor" , [1 1 1]                                  , ...
+              "tag"             , "unite_dir"                            );
     // Buttons
     // =========================================================================
     y = y - (slider_height+5*y_margin)
@@ -404,34 +404,34 @@ function cylinder_create_gui()
     btn_height=20;
     x=frame_x+80
     start_button = uicontrol(my_figure_handle                                   , ...
-                            "Position"             , [x y btn_width btn_height]                 , ...
-                            "Style"                , "pushbutton"                               , ...
-                            "String"               , "Start"                                    , ...
-                            "Fontsize"             , 14                                         , ...
-                            "BackgroundColor"      , [1 1 1]                                    , ...
-                            "callback"             , "start_simu()"                             , ...
-                            "tag"                  , "start_button"                             );
-    
+                 "Position"             , [x y btn_width btn_height]                 , ...
+                 "Style"                , "pushbutton"                               , ...
+                 "String"               , "Start"                                    , ...
+                 "Fontsize"             , 14                                         , ...
+                 "BackgroundColor"      , [1 1 1]                                    , ...
+                 "callback"             , "start_simu()"                             , ...
+                 "tag"                  , "start_button"                             );
+
     x=x+btn_width+btn_margin
     stop_button = uicontrol(my_figure_handle                                    , ...
-                           "Position"               , [x y btn_width btn_height]               , ...
-                           "Style"                  , "pushbutton"                             , ...
-                           "String"                 , "Stop"                                   , ...
-                           "Fontsize"               , 14                                       , ...
-                           "BackgroundColor"        , [1 1 1]                                  , ...
-                           "callback"               , "stop_simu"                              , ...
-                           "tag"                    , "stop_button"                            );
+                "Position"               , [x y btn_width btn_height]               , ...
+                "Style"                  , "pushbutton"                             , ...
+                "String"                 , "Stop"                                   , ...
+                "Fontsize"               , 14                                       , ...
+                "BackgroundColor"        , [1 1 1]                                  , ...
+                "callback"               , "stop_simu"                              , ...
+                "tag"                    , "stop_button"                            );
 
     x=x+btn_width+btn_margin
     clear_button = uicontrol(my_figure_handle                                   , ...
-                            "Position"               , [x y btn_width btn_height]               , ...
-                            "Style"                  , "pushbutton"                             , ...
-                            "String"                 , "Clear"                                  , ...
-                            "Fontsize"               , 14                                       , ...
-                            "BackgroundColor"        , [1 1 1]                                  , ...
-                            "callback"               , "clear_simu"                             , ...
-                            "tag"                    , "clear_button"                           );
-    
+                 "Position"               , [x y btn_width btn_height]               , ...
+                 "Style"                  , "pushbutton"                             , ...
+                 "String"                 , "Clear"                                  , ...
+                 "Fontsize"               , 14                                       , ...
+                 "BackgroundColor"        , [1 1 1]                                  , ...
+                 "callback"               , "clear_simu"                             , ...
+                 "tag"                    , "clear_button"                           );
+
     return
 endfunction
 
@@ -441,14 +441,14 @@ endfunction
 // =============================================================================
 
 function change_x(x)
-//x slider callback 
+//x slider callback
 // x is in [-0.9 0.9]
   slider_x     = findobj("tag", "slider_x");
   slider_y     = findobj("tag", "slider_y");
   slider_slope = findobj("tag", "slider_slope");
   slider_speed = findobj("tag", "slider_speed");
   slider_dir   = findobj("tag", "slider_dir");
+
   value_x       = findobj("tag", "value_x");
   if argn(2)==1 then
     slider_x.Value=(x+0.9)*100/1.8;
@@ -458,18 +458,18 @@ function change_x(x)
   end
   value_x.String=msprintf("%.3f",x)
   draw_initial_point(-0.9+slider_x.Value*1.8/100,slider_y.value*3/100,..
-                    slider_speed.Value*2/100,slider_dir.value*360/100,slider_slope.Value*70/100,%F);
+             slider_speed.Value*2/100,slider_dir.value*360/100,slider_slope.Value*70/100,%F);
 endfunction
 
 function change_y(y)
-//y slider callback 
+//y slider callback
 //y is in [0 3]
   slider_x     = findobj("tag", "slider_x");
   slider_y     = findobj("tag", "slider_y");
   slider_slope = findobj("tag", "slider_slope");
   slider_speed = findobj("tag", "slider_speed");
   slider_dir   = findobj("tag", "slider_dir");
+
   value_y       = findobj("tag", "value_y");
   if argn(2)==1 then
     slider_y.Value=(y)*100/3;
@@ -479,11 +479,11 @@ function change_y(y)
   end
   value_y.String=msprintf("%.3f",y)
   draw_initial_point(-0.9+slider_x.Value*1.8/100,slider_y.value*3/100,..
-                    slider_speed.Value*2/100,slider_dir.value*360/100,slider_slope.Value*70/100,%F);
+             slider_speed.Value*2/100,slider_dir.value*360/100,slider_slope.Value*70/100,%F);
 endfunction
 
 function change_speed(speed)
-//speed slider callback  
+//speed slider callback
 //speed is in [0 2]
   slider_x     = findobj("tag", "slider_x");
   slider_y     = findobj("tag", "slider_y");
@@ -500,11 +500,11 @@ function change_speed(speed)
   end
   value_speed.String=msprintf("%.2f",speed)
   draw_initial_point(-0.9+slider_x.Value*1.8/100,slider_y.value*3/100,..
-                    slider_speed.Value*2/100,slider_dir.value*360/100,slider_slope.Value*70/100,%F);
+             slider_speed.Value*2/100,slider_dir.value*360/100,slider_slope.Value*70/100,%F);
 endfunction
 
 function change_slope(slope)
-//slope slider callback  
+//slope slider callback
 //slope is in [0 70]
   slider_x     = findobj("tag", "slider_x");
   slider_y     = findobj("tag", "slider_y");
@@ -523,11 +523,11 @@ function change_slope(slope)
   g_pente=slope
   draw_cylinder(g_pente,%f);
   draw_initial_point(-0.9+slider_x.Value*1.8/100,slider_y.value*3/100,..
-                    slider_speed.Value*2/100,slider_dir.value*360/100,slider_slope.Value*70/100,%F);
+             slider_speed.Value*2/100,slider_dir.value*360/100,slider_slope.Value*70/100,%F);
 endfunction
 
 function change_dir(dir)
-//direction slider callback  
+//direction slider callback
 //dir is in [0 360]
   slider_x     = findobj("tag", "slider_x");
   slider_y     = findobj("tag", "slider_y");
@@ -544,11 +544,11 @@ function change_dir(dir)
   end
   value_dir.String=msprintf("%.0f",dir)
   draw_initial_point(-0.9+slider_x.Value*1.8/100,slider_y.value*3/100,..
-                    slider_speed.Value*2/100,slider_dir.value*360/100,slider_slope.Value*70/100,%F);
+             slider_speed.Value*2/100,slider_dir.value*360/100,slider_slope.Value*70/100,%F);
 endfunction
 
 function change_gravity(gravity)
-//gravity slider callback  
+//gravity slider callback
 //gravity is in [0 10]
   slider_x       = findobj("tag", "slider_x");
   slider_y       = findobj("tag", "slider_y");
@@ -566,7 +566,7 @@ function change_gravity(gravity)
   end
   value_g.String=msprintf("%.2f",gravity)
   //  draw_initial_point(-0.9+slider_x.Value*1.8/100,slider_y.value*3/100,..
-  //                slider_speed.Value*2/100,slider_dir.value*360/100,slider_slope.Value*70/100,%F);
+  //             slider_speed.Value*2/100,slider_dir.value*360/100,slider_slope.Value*70/100,%F);
 
 endfunction
 
@@ -584,7 +584,7 @@ function start_simu()
   slider_dir     = findobj("tag", "slider_dir");
   slider_g       = findobj("tag", "slider_gravity");
 
-  
+
   t              = 0:0.01:10; //1001 track points
 
   x       = -0.9+slider_x.Value*1.8/100
index f362eca..bc7ccfb 100644 (file)
@@ -10,3 +10,4 @@ subdemolist = ["Black hole"  ,"blackhole.dem.sce" ;
                "Sphere"      ,"sphere.dem.sce"    ];
 
 subdemolist(:,2) = demopath + subdemolist(:,2);
+clear demopath;
\ No newline at end of file
index f807097..12460e7 100644 (file)
@@ -6,62 +6,62 @@
 //
 
 function exesphere()
-// initialize the graphics and controls 
-  
+// initialize the graphics and controls
+
 // initial point
   g_r = 0.7;//radius
   g_t = 250;//theta
-  
+
   //initial speed
   g_V    = 1; //speed
-  g_Vdir = 180; //speed orientation 
-  
+  g_Vdir = 180; //speed orientation
+
+
 
-   
   // Figure parameters
   // =========================================================================
-  
+
   surface_frame_w = 600;     // surface frame width
   surface_frame_h = 600;     // surface frame height
-  
+
   control_frame_w = 600;
   control_frame_h = 200;
-  
+
   margin_x     = 15;      // Horizontal margin between each elements
   margin_y     = 15;      // Vertical margin between each elements
-  
+
   axes_figure_w = 2*margin_x + max(surface_frame_w,control_frame_w);
   axes_figure_h = 3*margin_y + surface_frame_h + control_frame_h;
-  
+
   // Figure creation
   // =========================================================================
-  
+
   my_figure_handle = scf(100001);
   clf(my_figure_handle,"reset");
-  
+
   my_figure_handle.background      = -2;
   my_figure_handle.figure_position = [0 0];
   my_figure_handle.axes_size       = [axes_figure_w axes_figure_h];
   my_figure_handle.figure_name     = gettext("Sphere");
-  
+
   //reserve The upper part of the graphic windows for the 3d view of the scene
   curAxe=gca();
   curAxe.axes_bounds = [0,0,1,3/4];
   draw_sphere();
   draw_initial_point(g_r,g_t,g_V,g_Vdir,%T);
-  
+
   //Create the controls in the window bottom
   // =========================================================================
 
   sphere_create_gui()
-  
+
   //Set control and graphics initial values
   // =========================================================================
   change_r(g_r)
   change_theta(g_t)
   change_speed(g_V)
   change_dir(g_Vdir)
-  
+
 endfunction
 
 // draw_sphere
@@ -69,7 +69,7 @@ endfunction
 
 function draw_sphere()
 // draw half of a sphere (the flow lines surface )
-  
+
    function [x,y,z]=sph(alp,tet)
      //parametric definition of a sphere
      x = r*cos(alp).*cos(tet)+orig(1)*ones(tet)
@@ -83,10 +83,10 @@ function draw_sphere()
    [xx,yy,zz]=eval3dp(sph,linspace(-%pi/2,0,40),linspace(0,%pi*2,20));
    // draw facets
    plot3d(xx,yy,zz);
-       
+
    endfunction
-   
-   
+
+
 // draw_initial_point
 // =============================================================================
 function draw_initial_point(g_r,g_t,g_V,g_Vdir,create)
@@ -98,32 +98,32 @@ function draw_initial_point(g_r,g_t,g_V,g_Vdir,create)
   dy1 = 0.1*g_V*sin(g_Vdir*%pi/180);
   my_figure_handle = scf(100001);
   my_figure_handle.immediate_drawing = "off";
-       
+
   if create then
     //create the graphical object used to visualize the trajectory
-    xpoly(0,0) 
+    xpoly(0,0)
     traj_handle                        =gce();
-    traj_handle.thickness              = 2; 
+    traj_handle.thickness              = 2;
     traj_handle.foreground             = 5;
     //create the graphical object used to visualize the initial speed
-    xpoly(0,0) 
+    xpoly(0,0)
     speed_handle                       =  gce();
     speed_handle.thickness             =  1;
     speed_handle.foreground            =  5;
     speed_handle.polyline_style        =  4;
     speed_handle.arrow_size_factor     =  2;
     //create the graphical objects used to visualize the initial position
-    param3d([x-r,x+r],[y,y],[z,z]);  
-    e1                                 = gce(); 
-    e1.thickness                       = 1; 
+    param3d([x-r,x+r],[y,y],[z,z]);
+    e1                                 = gce();
+    e1.thickness                       = 1;
     e1.foreground                      = 5;
-    param3d([x,x],[y-r,y+r],[z,z]);  
-    e2                                 = gce(); 
-    e2.thickness                       = 1; 
+    param3d([x,x],[y-r,y+r],[z,z]);
+    e2                                 = gce();
+    e2.thickness                       = 1;
     e2.foreground                      = 5;
-    param3d([x,x],[y,y],[z-r,z+r]);  
-    e3                                 = gce(); 
-    e3.thickness                       = 1; 
+    param3d([x,x],[y,y],[z-r,z+r]);
+    e3                                 = gce();
+    e3.thickness                       = 1;
     e3.foreground                      = 5;
     glue([traj_handle speed_handle e1 e2 e3])
   else
@@ -133,10 +133,10 @@ function draw_initial_point(g_r,g_t,g_V,g_Vdir,create)
     initial(2).data = [x,y-r,z;x,y+r,z];
     initial(3).data = [x-r,y,z;x+r,y,z];
   end
-  z1=-sqrt(1-(x+dx1)^2-(y+dy1)^2)+r 
+  z1=-sqrt(1-(x+dx1)^2-(y+dy1)^2)+r
   initial(4).data = [x,y,z;x+dx1,y+dy1,z1];
 
-  my_figure_handle.immediate_drawing = "on";   
+  my_figure_handle.immediate_drawing = "on";
 endfunction
 
 // =============================================================================
@@ -145,237 +145,237 @@ endfunction
 
 function sphere_create_gui()
   //initial values
-       
-       g_t     = 0;
-       g_r     = 0;
-       g_speed = 0;
-       g_Vdir   = 0;
-       
-       my_figure_handle = scf(100001);
-       
-       axes_size_figure = my_figure_handle.axes_size;
-       axes_figure_w    = axes_size_figure(1);
-       axes_figure_h    = axes_size_figure(2);
-       
-       frame_x      = 25;
-       frame_y      = 200;
-       
-       slider_height   = 15;
-       slider_width    = 140;
-       value_width     = 30;
-       unit_width      = 30;
-       text_width      = 50;
-       y_margin        = 5;
+
+    g_t     = 0;
+    g_r     = 0;
+    g_speed = 0;
+    g_Vdir   = 0;
+
+    my_figure_handle = scf(100001);
+
+    axes_size_figure = my_figure_handle.axes_size;
+    axes_figure_w    = axes_size_figure(1);
+    axes_figure_h    = axes_size_figure(2);
+
+    frame_x      = 25;
+    frame_y      = 200;
+
+    slider_height   = 15;
+    slider_width    = 140;
+    value_width     = 30;
+    unit_width      = 30;
+    text_width      = 50;
+    y_margin        = 5;
         x_margin        = 10;
-       title_width     =  text_width + slider_width + value_width + unit_width +3*x_margin
-       
-       x_text         = frame_x
-       x_slider        = x_text + text_width + x_margin;
-       x_value         = x_slider + slider_width+x_margin;
-       x_unit          = x_value  + value_width+x_margin;
-       
-       y               = frame_y-40;
-       
-       // Title position
-       // =========================================================================
-       
-       title_r = uicontrol(my_figure_handle                             , ...
-               "position"            , [x_text y title_width slider_height+y_margin]   , ...
-               "Style"               , "text"                                   , ...
-               "String"              , "Starting point"                         , ...
-               "BackgroundColor"     , [1 1 1]                                  , ...
-               "Fontsize"            , 16                                       , ...
-               "horizontalalignment" , "center"                                 , ...
-               "tag"                 , "title_r"                            );
-       
-       // Slider "r"
-       // =========================================================================
-       y = y - (slider_height+y_margin)
-       text_r = uicontrol(my_figure_handle                              , ...
-               "position"          , [x_text y text_width slider_height]    , ...
-               "Style"             , "text"                                 , ...
-               "String"            , "r"                                    , ...
-               "BackgroundColor"   , [1 1 1]                                , ...
-               "tag"               , "text_r"                           );
-       
-       slider_r = uicontrol(my_figure_handle                            , ...
-               "position"          , [x_slider y slider_width slider_height], ...
-               "Style"             , "slider"                               , ...
-               "Value"             , g_r                                 , ...
-               "Min"               , 0                                      , ...
-               "Max"               , 100                                      , ...
-               "callback"          , "change_r()"                           , ...
-               "tag"               , "slider_r"                         );
-       
-       value_r = uicontrol(my_figure_handle                             , ...
-               "position"          , [x_value  y value_width slider_height] , ...
-               "Style"             , "text"                                 , ...
-               "String"            , string(g_r)                            , ...
-               "BackgroundColor"   , [1 1 1]                                , ...
-               "tag"               , "value_r"                          );
-       
-       unite_r = uicontrol(my_figure_handle                             , ...
-               "position"          , [x_unit y unit_width slider_height]    , ...
-               "Style"             , "text"                                 , ...
-               "String"            , "(m)"                                  , ...
-               "BackgroundColor"   , [1 1 1]                                , ...
-               "tag"               , "unite_r"                          );
-       
-       // Slider theta
-       // =========================================================================
-       y = y - (slider_height+y_margin)
-       text_theta = uicontrol(my_figure_handle                          , ...
-               "position"       , [x_text y text_width slider_height]       , ...
-               "Style"          , "text"                                    , ...
-               "String"         , "theta"                                   , ...
-               "BackgroundColor", [1 1 1]                                   , ...
-               "tag"            , "text_theta"                              );
-       
-       slider_theta = uicontrol(my_figure_handle                        , ...
-               "position"  , [x_slider y slider_width slider_height]        , ...
-               "Style"     , "slider"                                       , ...
-               "Min"       , 0                                              , ...
-               "Max"       , 100                                            , ...
-               "Value"     , g_t                                            , ...
-               "callback"  , "change_theta()"                                   , ...
-               "tag"       , "slider_theta"                                 );
-       
-       value_theta = uicontrol(my_figure_handle                         , ...
-               "position"        , [x_value  y value_width  slider_height]  , ...
-               "Style"           , "text"                                   , ...
-               "String"          , string(g_t)                              , ...
-               "BackgroundColor" , [1 1 1]                                  , ...
-               "tag"             , "value_theta"                            );
-       
-       unite_theta = uicontrol(my_figure_handle                         , ...
-               "position"        , [x_unit y unit_width slider_height]      , ...
-               "Style"           , "text"                                   , ...
-               "String"          , "(deg)"                                  , ...
-               "BackgroundColor" , [1 1 1]                                  , ...
-               "tag"             , "unite_theta"                            );
-       //---------------------------------------------------------------------------
-       //second column 
-       x_text          = frame_x + title_width + 3*x_margin
-       x_slider        = x_text + text_width + x_margin;
-       x_value         = x_slider + slider_width+x_margin;
-       x_unit          = x_value  + value_width+x_margin;
-       
-       y               = frame_y-40;
-
-       // Title speed
-       // =========================================================================
-       
-       title_speed = uicontrol(my_figure_handle                             , ...
-               "position"            , [x_text y title_width slider_height+y_margin],...
-               "Style"               , "text"                                   , ...
-               "String"              , "Initial speed"                          , ...
-               "BackgroundColor"     , [1 1 1]                                  , ...
-               "Fontsize"            , 16                                       , ...
-               "horizontalalignment" , "center"                                 , ...
-               "tag"                 , "title_speed"                            );
-       
-       // Slider speed
-       // =========================================================================
-       y = y - (slider_height+y_margin)
-       text_speed = uicontrol(my_figure_handle                          , ...
-               "position"          , [x_text y text_width slider_height]    , ...
-               "Style"             , "text"                                 , ...
-               "String"            , "speed"                                , ...
-               "BackgroundColor"   , [1 1 1]                                , ...
-               "tag"               , "text_speed"                           );
-       
-       slider_speed = uicontrol(my_figure_handle                        , ...
-               "position"          , [x_slider y slider_width slider_height], ...
-               "Style"             , "slider"                               , ...
-               "Value"             , g_speed                                , ...
-               "Min"               , 0                                      , ...
-               "Max"               , 100                                      , ...
-               "callback"          , "change_speed()"                       , ...
-               "tag"               , "slider_speed"                         );
-       
-       value_speed = uicontrol(my_figure_handle                         , ...
-               "position"          , [x_value  y value_width slider_height] , ...
-               "Style"             , "text"                                 , ...
-               "String"            , string(g_speed)                        , ...
-               "BackgroundColor"   , [1 1 1]                                , ...
-               "tag"               , "value_speed"                          );
-       
-       unite_speed = uicontrol(my_figure_handle                         , ...
-               "position"          , [x_unit y unit_width slider_height]    , ...
-               "Style"             , "text"                                 , ...
-               "String"            , "(m/s)"                                  , ...
-               "BackgroundColor"   , [1 1 1]                                , ...
-               "tag"               , "unite_speed"                          );
-       
-       // Slider direction
-       // =========================================================================
-       y = y - (slider_height+y_margin)
-       text_dir = uicontrol(my_figure_handle                            , ...
-               "position"       , [x_text y text_width slider_height]       , ...
-               "Style"          , "text"                                    , ...
-               "String"         , "direction"                                   , ...
-               "BackgroundColor", [1 1 1]                                   , ...
-               "tag"            , "text_dir"                              );
-       
-       slider_dir = uicontrol(my_figure_handle                          , ...
-               "position"  , [x_slider y slider_width slider_height]        , ...
-               "Style"     , "slider"                                       , ...
-               "Min"       , 0                                              , ...
-               "Max"       , 100                                            , ...
-               "Value"     , g_Vdir                                           , ...
-               "callback"  , "change_dir()"                                   , ...
-               "tag"       , "slider_dir"                                 );
-       
-       value_dir = uicontrol(my_figure_handle                           , ...
-               "position"        , [x_value  y value_width  slider_height]  , ...
-               "Style"           , "text"                                   , ...
-               "String"          , string(g_Vdir)                              , ...
-               "BackgroundColor" , [1 1 1]                                  , ...
-               "tag"             , "value_dir"                            );
-       
-       unite_dir = uicontrol(my_figure_handle                           , ...
-               "position"        , [x_unit y unit_width slider_height]      , ...
-               "Style"           , "text"                                   , ...
-               "String"          , "(deg)"                                  , ...
-               "BackgroundColor" , [1 1 1]                                  , ...
-               "tag"             , "unite_dir"                            );
-       // Buttons
-       // =========================================================================
-       y = y - (slider_height+5*y_margin)
-       btn_width=100;
-       btn_margin=50;
-       btn_height=20;
-       x=frame_x+80
-       start_button = uicontrol(my_figure_handle                                   , ...
-               "Position"             , [x y btn_width btn_height]                 , ...
-               "Style"                , "pushbutton"                               , ...
-               "String"               , "Start"                                    , ...
-               "Fontsize"             , 14                                         , ...
-               "BackgroundColor"      , [1 1 1]                                    , ...
-               "callback"             , "start_simu()"                             , ...
-               "tag"                  , "start_button"                             );
-       
-       x=x+btn_width+btn_margin
-       stop_button = uicontrol(my_figure_handle                                    , ...
-               "Position"               , [x y btn_width btn_height]               , ...
-               "Style"                  , "pushbutton"                             , ...
-               "String"                 , "Stop"                                   , ...
-               "Fontsize"               , 14                                       , ...
-               "BackgroundColor"        , [1 1 1]                                  , ...
-               "callback"               , "stop_simu"                              , ...
-               "tag"                    , "stop_button"                            );
-
-       x=x+btn_width+btn_margin
-       clear_button = uicontrol(my_figure_handle                                   , ...
-               "Position"               , [x y btn_width btn_height]               , ...
-               "Style"                  , "pushbutton"                             , ...
-               "String"                 , "Clear"                                  , ...
-               "Fontsize"               , 14                                       , ...
-               "BackgroundColor"        , [1 1 1]                                  , ...
-               "callback"               , "clear_simu"                             , ...
-               "tag"                    , "clear_button"                           );
-       
-       return
+    title_width     =  text_width + slider_width + value_width + unit_width +3*x_margin
+
+    x_text         = frame_x
+    x_slider        = x_text + text_width + x_margin;
+    x_value         = x_slider + slider_width+x_margin;
+    x_unit          = x_value  + value_width+x_margin;
+
+    y               = frame_y-40;
+
+    // Title position
+    // =========================================================================
+
+    title_r = uicontrol(my_figure_handle                             , ...
+        "position"            , [x_text y title_width slider_height+y_margin]   , ...
+        "Style"               , "text"                                   , ...
+        "String"              , "Starting point"                         , ...
+        "BackgroundColor"     , [1 1 1]                                  , ...
+        "Fontsize"            , 16                                       , ...
+        "horizontalalignment" , "center"                                 , ...
+        "tag"                 , "title_r"                            );
+
+    // Slider "r"
+    // =========================================================================
+    y = y - (slider_height+y_margin)
+    text_r = uicontrol(my_figure_handle                              , ...
+        "position"          , [x_text y text_width slider_height]    , ...
+        "Style"             , "text"                                 , ...
+        "String"            , "r"                                    , ...
+        "BackgroundColor"   , [1 1 1]                                , ...
+        "tag"               , "text_r"                           );
+
+    slider_r = uicontrol(my_figure_handle                            , ...
+        "position"          , [x_slider y slider_width slider_height], ...
+        "Style"             , "slider"                               , ...
+        "Value"             , g_r                                 , ...
+        "Min"               , 0                                      , ...
+        "Max"               , 100                                      , ...
+        "callback"          , "change_r()"                           , ...
+        "tag"               , "slider_r"                         );
+
+    value_r = uicontrol(my_figure_handle                             , ...
+        "position"          , [x_value  y value_width slider_height] , ...
+        "Style"             , "text"                                 , ...
+        "String"            , string(g_r)                            , ...
+        "BackgroundColor"   , [1 1 1]                                , ...
+        "tag"               , "value_r"                          );
+
+    unite_r = uicontrol(my_figure_handle                             , ...
+        "position"          , [x_unit y unit_width slider_height]    , ...
+        "Style"             , "text"                                 , ...
+        "String"            , "(m)"                                  , ...
+        "BackgroundColor"   , [1 1 1]                                , ...
+        "tag"               , "unite_r"                          );
+
+    // Slider theta
+    // =========================================================================
+    y = y - (slider_height+y_margin)
+    text_theta = uicontrol(my_figure_handle                          , ...
+        "position"       , [x_text y text_width slider_height]       , ...
+        "Style"          , "text"                                    , ...
+        "String"         , "theta"                                   , ...
+        "BackgroundColor", [1 1 1]                                   , ...
+        "tag"            , "text_theta"                              );
+
+    slider_theta = uicontrol(my_figure_handle                        , ...
+        "position"  , [x_slider y slider_width slider_height]        , ...
+        "Style"     , "slider"                                       , ...
+        "Min"       , 0                                              , ...
+        "Max"       , 100                                            , ...
+        "Value"     , g_t                                            , ...
+        "callback"  , "change_theta()"                                   , ...
+        "tag"       , "slider_theta"                                 );
+
+    value_theta = uicontrol(my_figure_handle                         , ...
+        "position"        , [x_value  y value_width  slider_height]  , ...
+        "Style"           , "text"                                   , ...
+        "String"          , string(g_t)                              , ...
+        "BackgroundColor" , [1 1 1]                                  , ...
+        "tag"             , "value_theta"                            );
+
+    unite_theta = uicontrol(my_figure_handle                         , ...
+        "position"        , [x_unit y unit_width slider_height]      , ...
+        "Style"           , "text"                                   , ...
+        "String"          , "(deg)"                                  , ...
+        "BackgroundColor" , [1 1 1]                                  , ...
+        "tag"             , "unite_theta"                            );
+    //---------------------------------------------------------------------------
+    //second column
+    x_text          = frame_x + title_width + 3*x_margin
+    x_slider        = x_text + text_width + x_margin;
+    x_value         = x_slider + slider_width+x_margin;
+    x_unit          = x_value  + value_width+x_margin;
+
+    y               = frame_y-40;
+
+    // Title speed
+    // =========================================================================
+
+    title_speed = uicontrol(my_figure_handle                             , ...
+        "position"            , [x_text y title_width slider_height+y_margin],...
+        "Style"               , "text"                                   , ...
+        "String"              , "Initial speed"                          , ...
+        "BackgroundColor"     , [1 1 1]                                  , ...
+        "Fontsize"            , 16                                       , ...
+        "horizontalalignment" , "center"                                 , ...
+        "tag"                 , "title_speed"                            );
+
+    // Slider speed
+    // =========================================================================
+    y = y - (slider_height+y_margin)
+    text_speed = uicontrol(my_figure_handle                          , ...
+        "position"          , [x_text y text_width slider_height]    , ...
+        "Style"             , "text"                                 , ...
+        "String"            , "speed"                                , ...
+        "BackgroundColor"   , [1 1 1]                                , ...
+        "tag"               , "text_speed"                           );
+    
+    slider_speed = uicontrol(my_figure_handle                        , ...
+        "position"          , [x_slider y slider_width slider_height], ...
+        "Style"             , "slider"                               , ...
+        "Value"             , g_speed                                , ...
+        "Min"               , 0                                      , ...
+        "Max"               , 100                                      , ...
+        "callback"          , "change_speed()"                       , ...
+        "tag"               , "slider_speed"                         );
+    
+    value_speed = uicontrol(my_figure_handle                         , ...
+        "position"          , [x_value  y value_width slider_height] , ...
+        "Style"             , "text"                                 , ...
+        "String"            , string(g_speed)                        , ...
+        "BackgroundColor"   , [1 1 1]                                , ...
+        "tag"               , "value_speed"                          );
+    
+    unite_speed = uicontrol(my_figure_handle                         , ...
+        "position"          , [x_unit y unit_width slider_height]    , ...
+        "Style"             , "text"                                 , ...
+        "String"            , "(m/s)"                                  , ...
+        "BackgroundColor"   , [1 1 1]                                , ...
+        "tag"               , "unite_speed"                          );
+    
+    // Slider direction
+    // =========================================================================
+    y = y - (slider_height+y_margin)
+    text_dir = uicontrol(my_figure_handle                            , ...
+        "position"       , [x_text y text_width slider_height]       , ...
+        "Style"          , "text"                                    , ...
+        "String"         , "direction"                                   , ...
+        "BackgroundColor", [1 1 1]                                   , ...
+        "tag"            , "text_dir"                              );
+    
+    slider_dir = uicontrol(my_figure_handle                          , ...
+        "position"  , [x_slider y slider_width slider_height]        , ...
+        "Style"     , "slider"                                       , ...
+        "Min"       , 0                                              , ...
+        "Max"       , 100                                            , ...
+        "Value"     , g_Vdir                                           , ...
+        "callback"  , "change_dir()"                                   , ...
+        "tag"       , "slider_dir"                                 );
+    
+    value_dir = uicontrol(my_figure_handle                           , ...
+        "position"        , [x_value  y value_width  slider_height]  , ...
+        "Style"           , "text"                                   , ...
+        "String"          , string(g_Vdir)                              , ...
+        "BackgroundColor" , [1 1 1]                                  , ...
+        "tag"             , "value_dir"                            );
+    
+    unite_dir = uicontrol(my_figure_handle                           , ...
+        "position"        , [x_unit y unit_width slider_height]      , ...
+        "Style"           , "text"                                   , ...
+        "String"          , "(deg)"                                  , ...
+        "BackgroundColor" , [1 1 1]                                  , ...
+        "tag"             , "unite_dir"                            );
+    // Buttons
+    // =========================================================================
+    y = y - (slider_height+5*y_margin)
+    btn_width=100;
+    btn_margin=50;
+    btn_height=20;
+    x=frame_x+80
+    start_button = uicontrol(my_figure_handle                                   , ...
+        "Position"             , [x y btn_width btn_height]                 , ...
+        "Style"                , "pushbutton"                               , ...
+        "String"               , "Start"                                    , ...
+        "Fontsize"             , 14                                         , ...
+        "BackgroundColor"      , [1 1 1]                                    , ...
+        "callback"             , "start_simu()"                             , ...
+        "tag"                  , "start_button"                             );
+    
+    x=x+btn_width+btn_margin
+    stop_button = uicontrol(my_figure_handle                                    , ...
+        "Position"               , [x y btn_width btn_height]               , ...
+        "Style"                  , "pushbutton"                             , ...
+        "String"                 , "Stop"                                   , ...
+        "Fontsize"               , 14                                       , ...
+        "BackgroundColor"        , [1 1 1]                                  , ...
+        "callback"               , "stop_simu"                              , ...
+        "tag"                    , "stop_button"                            );
+
+    x=x+btn_width+btn_margin
+    clear_button = uicontrol(my_figure_handle                                   , ...
+        "Position"               , [x y btn_width btn_height]               , ...
+        "Style"                  , "pushbutton"                             , ...
+        "String"                 , "Clear"                                  , ...
+        "Fontsize"               , 14                                       , ...
+        "BackgroundColor"        , [1 1 1]                                  , ...
+        "callback"               , "clear_simu"                             , ...
+        "tag"                    , "clear_button"                           );
+    
+    return
 endfunction
 
 // =============================================================================
@@ -473,7 +473,7 @@ function start_simu()
   slider_dir   = findobj("tag", "slider_dir");
   t =            0:0.01:15
   Y = calculate_traj(slider_r.Value/100,slider_theta.value*360/100, ...
-                    slider_speed.Value*20/100,slider_dir.value*360/100,t)
+             slider_speed.Value*20/100,slider_dir.value*360/100,t)
   x = Y(1,:)
   y = Y(3,:)
   r = 0.1; //bias to have the curve above the surface
index 3b5e48f..8791e60 100644 (file)
@@ -5,7 +5,10 @@
 // This file is released into the public domain
 
 mode(-1);
+path = pathconvert(get_absolute_file_path('n_pendulum.dem.sce'),%t,%t) 
+exec(path + "n_pendulum.sci");
 
-path=pathconvert(get_absolute_file_path('n_pendulum.dem.sce'),%t,%t)   
-exec(path+"n_pendulum.sci");
 demo_pendulum()
+
+clear path
+clear demo_pendulum;
index 5ce51b2..02c72cd 100644 (file)
 //
 
 function demo_pendulum()
-       if ~(haveacompiler()) then
-               messagebox(["Scilab doesn''t find a C compiler","This demo is disabled"],"modal");
-       else
-               npend_build_and_load();
-               n  = np();
-               r  = ones(1,n);
-               m  = ones(1,n);
-               j  = ones(1,n);
-               g  = 9.81;
-               y0 = 0*ones(2*n,1);tt=0:0.05:10;
-               yt = ode(y0,0,tt,"npend");
-               draw_chain_from_angles(yt(1:$/2,:),r,1);
-       end
-endfunction
 
+  function []=npend_build_and_load()
 
-function []=npend_build_and_load()
-       
-       // since this demo can be run by someone
-       // who has no write access in this directory
-       // we use TMPDIR
-       
-       if ~c_link('npend') then
-               path   = SCI+"/modules/differential_equations/demos/n_pendulum/Maple/"
-               cdpath = pwd();
-               chdir(TMPDIR);
-               fcode = mgetl(path+'dlslv.f');mputl(fcode,'dlslv.f');
-               fcode = mgetl(path+'ener.f');mputl(fcode,'ener.f');
-               fcode = mgetl(path+'np.f');mputl(fcode,'np.f');
-               fcode = mgetl(path+'npend.f');mputl(fcode,'npend.f');
-               files = ['npend.f','np.f','ener.f','dlslv.f' ];
-               ilib_for_link(['npend';'np';'ener'],files,[],"f");
-               exec loader.sce
-               chdir(cdpath);
-       end
-endfunction
+    // since this demo can be run by someone
+    // who has no write access in this directory
+    // we use TMPDIR
 
+    if ~c_link('npend') then
+      path   = SCI+"/modules/differential_equations/demos/n_pendulum/Maple/"
+      cdpath = pwd();
+      chdir(TMPDIR);
+      fcode = mgetl(path+'dlslv.f');mputl(fcode,'dlslv.f');
+      fcode = mgetl(path+'ener.f');mputl(fcode,'ener.f');
+      fcode = mgetl(path+'np.f');mputl(fcode,'np.f');
+      fcode = mgetl(path+'npend.f');mputl(fcode,'npend.f');
+      files = ['npend.f','np.f','ener.f','dlslv.f' ];
+      ilib_verbose(0);
+      ilib_for_link(['npend';'np';'ener'],files,[],"f");
+      exec("loader.sce",-1);
+      chdir(cdpath);
+    end
+  endfunction
 
-function [n]=np()
-       // Return the size  of the Fortran pendulum 
-       n=1;
-       n=fort('np',n,1,'i','sort',1);
-endfunction 
 
+  function [n]=np()
+    // Return the size  of the Fortran pendulum
+    n=1;
+    n=fort('np',n,1,'i','sort',1);
+  endfunction
+
+
+  function [ydot]=npend ( t, th)
+    // Fortran version
+    //    data r  / 1.0, 1.0, 1.0, 1.0 /
+    //    data m  / 1.0, 1.0, 1.0, 1.0 /
+    //    data j  / 0.3, 0.3, 0.3, 0.3 /
+    ydot=ones(6,1)
+    ydot=fort('npend',3,1,'i',t,2,'d',th,3,'d',ydot,4,'d','sort',4);
+  endfunction
+
+
+  function [E]=ener( th)
+    E=0.0;
+    E=fort('ener',th,1,'d',E,2,'d','sort',2);
+  endfunction
+
+
+  function draw_chain_from_angles(a,r,job)
+    // a the angles , a(i,j) is the angle of node i a time t(j)
+    // r the segments half length
+    if argn(2)<3 then job=0,end
+    n2=size(a,2);
+    // build the links positions
+    x=[0*ones(1,n2);cumsum(2*diag(r)*cos(a),1)];
+    y=[0*ones(1,n2);cumsum(2*diag(r)*sin(a),1)];
+    draw_chain_from_coor(x,y,job)
+  endfunction
 
-function [ydot]=npend ( t, th)
-       // Fortran version
-       //      data r  / 1.0, 1.0, 1.0, 1.0 /
-       //      data m  / 1.0, 1.0, 1.0, 1.0 /
-       //      data j  / 0.3, 0.3, 0.3, 0.3 /
-       ydot=ones(6,1)
-       ydot=fort('npend',3,1,'i',t,2,'d',th,3,'d',ydot,4,'d','sort',4);
-endfunction
 
+  function draw_chain_from_coor(x,y,job)
 
-function [E]=ener( th)
-       E=0.0;
-       E=fort('ener',th,1,'d',E,2,'d','sort',2);
-endfunction 
+    my_handle = scf(100001);
+    clf(my_handle,"reset");
+    my_handle.immediate_drawing = "off"; //not to see the intermediate graphic steps
+  
+    // x,y the coordinates ,
+    //   x(i,j), y(i,j) is the coordinate of node i a time t(j)
+    // r the segments half length
+    if argn(2)<3 then job=0,end
+    [n1,n2]=size(x);
 
+    //set the frame
+    a=gca()
+    a.data_bounds=2*[-n1,-n1;n1,0];
 
-function draw_chain_from_angles(a,r,job)
-       // a the angles , a(i,j) is the angle of node i a time t(j)
-       // r the segments half length
-       if argn(2)<3 then job=0,end
-       n2=size(a,2);
-       // build the links positions
-       x=[0*ones(1,n2);cumsum(2*diag(r)*cos(a),1)];
-       y=[0*ones(1,n2);cumsum(2*diag(r)*sin(a),1)];
-       draw_chain_from_coor(x,y,job)
+    //create one polyline and one polymark with the initial position
+    xsegs([x(1:$-1,1)';x(2:$,1)'],[y(1:$-1,1)';y(2:$,1)'],1:n1-1);
+    p=gce();
+    p.thickness=4;
+    xpoly(x(:,1),y(:,1),"lines");
+    p1=gce();
+
+    p1.mark_style=3;
+    p1.mark_size_unit='point';
+    p1.mark_size=6;
+
+    if job==1 then
+      //bound trajectory
+      xpoly(x($,1)*ones(2,1),y($,1)*ones(2,1),'lines');
+      t=gce();t.line_style=2;
+    end
+
+    my_handle.immediate_drawing = "on";
+
+    ind=[1;(2:n1-1)'.*.ones(2,1);n1]
+    realtimeinit(0.1)
+    for j=1:n2,
+  
+      if ~is_handle_valid(my_handle) then
+        break;
+      end
+    
+      realtime(j) //to slow down the drawing
+    
+      if is_handle_valid(my_handle) then
+        my_handle.immediate_drawing = "off";
+      end
+
+      // update chain coordinates
+      if is_handle_valid(p1) then
+        p1.data = [x(:,j),y(:,j)];
+      end
+    
+      if is_handle_valid(p) then
+        p.data = [x(ind,j),y(ind,j)];
+      end
+    
+      // add a trajectory point
+      if job==1 & is_handle_valid(t) then 
+        t.data=[t.data;[x($,j),y($,j)]];
+      end
+
+      if is_handle_valid(my_handle) then    
+        my_handle.immediate_drawing = "on";
+      end
+    end
 endfunction
 
 
-function draw_chain_from_coor(x,y,job)
-       
-       my_handle = scf(100001);
-       clf(my_handle,"reset");
-       my_handle.immediate_drawing = "off"; //not to see the intermediate graphic steps
-       
-       // x,y the coordinates ,
-       //     x(i,j), y(i,j) is the coordinate of node i a time t(j)
-       // r the segments half length
-       if argn(2)<3 then job=0,end
-       [n1,n2]=size(x);
-       
-       //set the frame
-       a=gca()
-       a.data_bounds=2*[-n1,-n1;n1,0];
-       
-       //create one polyline and one polymark with the initial position
-       xsegs([x(1:$-1,1)';x(2:$,1)'],[y(1:$-1,1)';y(2:$,1)'],1:n1-1);
-       p=gce();
-       p.thickness=4;
-       xpoly(x(:,1),y(:,1),"lines");
-       p1=gce();
-       
-       p1.mark_style=3;
-       p1.mark_size_unit='point';
-       p1.mark_size=6;
-       
-       if job==1 then
-               //bound trajectory
-               xpoly(x($,1)*ones(2,1),y($,1)*ones(2,1),'lines');
-               t=gce();t.line_style=2;
-       end
-       
-       my_handle.immediate_drawing = "on";
-       
-       ind=[1;(2:n1-1)'.*.ones(2,1);n1]
-       realtimeinit(0.1)
-       for j=1:n2,
-               realtime(j) //to slow down the drawing
-               my_handle.immediate_drawing = "off";
-               // update chain coordinates
-               p1.data = [x(:,j),y(:,j)]; 
-               p.data = [x(ind,j),y(ind,j)]; 
-               // add a trajectory point
-               if job==1 then t.data=[t.data;[x($,j),y($,j)]],end
-               my_handle.immediate_drawing = "on";
-       end
-       
+  if ~(haveacompiler()) then
+    messagebox(["Scilab doesn''t find a C compiler","This demo is disabled"],"modal");
+  else
+    npend_build_and_load();
+    n  = np();
+    r  = ones(1,n);
+    m  = ones(1,n);
+    j  = ones(1,n);
+    g  = 9.81;
+    y0 = 0*ones(2*n,1);tt=0:0.05:10;
+    yt = ode(y0,0,tt,"npend");
+    draw_chain_from_angles(yt(1:$/2,:),r,1);
+  end
+  
 endfunction
+
+
index 4956d08..2bf7b6d 100644 (file)
@@ -14,3 +14,4 @@ subdemolist = ["Simple ODE"                   ,"ode_simple/ode_simple.dem.sce"
                "Lotka-Volterra vector field"  ,"ode_lotka/ode_lotka.dem.sce"         ];
 
 subdemolist(:,2) = demopath + subdemolist(:,2);
+clear demopath;
\ No newline at end of file
index 1086921..746f496 100644 (file)
@@ -2,8 +2,12 @@
 // Copyright (C) 2008 - INRIA
 //
 // This file is released into the public domain
-oldln=lines();lines(0)
-text = ["Examples of ODE''s in 1 dimension"; ..
+
+function demo_ode_1dvect()
+
+  oldln=lines();
+  lines(0)
+  text = ["Examples of ODE''s in 1 dimension"; ..
         "A trajectory is plotted by clicking on the"; ..
         "  LEFT button of the mouse."; ..
         "  The trajectory is updated as you move the mouse."; ..
@@ -11,71 +15,72 @@ text = ["Examples of ODE''s in 1 dimension"; ..
         "You can start over by clicking on the LEFT button again"; ..
         "  or stop everything by clicking on the RIGHT button." ];
 
-messagebox(text,"modal");
-
-function yprim=f(t,y),yprim=y^2-t;endfunction
-function z=g(t,y),z=[y-ymin;y+ymax];endfunction
-
-tmin = -3;
-tmax =  5;
-ymin = -3;
-ymax =  3;
+  messagebox(text,"modal");
 
+  function yprim=f(t,y),yprim=y^2-t;endfunction
+  function z=g(t,y),z=[y-ymin;y+ymax];endfunction
 
-t = tmin:1:tmax;
-y = ymin:1:ymax;
+  tmin = -3;
+  tmax =  5;
+  ymin = -3;
+  ymax =  3;
 
+  t = tmin:1:tmax;
+  y = ymin:1:ymax;
 
-my_handle = scf(100001);
-clf(my_handle,"reset");
-demo_viewCode("ode_1dvect.dem.sce");
+  my_handle = scf(100001);
+  clf(my_handle,"reset");
+  demo_viewCode("ode_1dvect.dem.sce");
 
-nt = size(t,"*");
-ny = size(y,"*");
-fx = ones(nt,ny);
-fy = feval(t,y,f);
-champ(t,y,fx,fy);
-xlabel('t','fontsize',3)
-ylabel('y','fontsize',3)
-a=gca();a.margins(3)=0.2;
-title([_("ODE 1D vector field")
+  nt = size(t,"*");
+  ny = size(y,"*");
+  fx = ones(nt,ny);
+  fy = feval(t,y,f);
+  champ(t,y,fx,fy);
+  xlabel('t','fontsize',3)
+  ylabel('y','fontsize',3)
+  a=gca();
+  a.margins(3)=0.2;
+  title([_("ODE 1D vector field")
        "dy/dt=  y^2 - t"],'fontsize',3)
 
+  oldt0 = 10*tmax;
+  oldy0 = 10*ymax;
+  dt                 = 0.1;
+  dy                 = 0.1;
 
+  while(%T)
+    [b,t0,y0]=xclick();
+    if or(b==[2 5 -1000]) then break,end;
+    if or(b==[0 3])& tmin<t0 & t0<tmax & ymin<y0 & y0<ymax then
+      t1=t0:0.1:tmax;
+      [sol1,rd]=ode("root",y0,t0,t1,1.d-2,1.d-4,f,2,g);
+      xpoly(t1(1:size(sol1,"*"))',sol1');
+      p1=gce();p1.thickness=2;p1.foreground=5;
 
-oldt0 = 10*tmax;
-oldy0 = 10*ymax;
-dt                 = 0.1;
-dy                 = 0.1;
+      t2=t0:-0.1:tmin;
+      [sol2,rd]=ode("root",y0,t0,t2,1.d-2,1.d-4,f,2,g);
+      xpoly(t2(1:size(sol2,"*"))',sol2');
 
-while(%T)
-  [b,t0,y0]=xclick();
-  if or(b==[2 5 -1000]) then break,end;
-  if or(b==[0 3])& tmin<t0 & t0<tmax & ymin<y0 & y0<ymax then
-    t1=t0:0.1:tmax;
-    [sol1,rd]=ode("root",y0,t0,t1,1.d-2,1.d-4,f,2,g);
-    xpoly(t1(1:size(sol1,"*"))',sol1');
-    p1=gce();p1.thickness=2;p1.foreground=5;
-
-    t2=t0:-0.1:tmin;
-    [sol2,rd]=ode("root",y0,t0,t2,1.d-2,1.d-4,f,2,g);
-    xpoly(t2(1:size(sol2,"*"))',sol2');
-
-    p2=gce();p2.thickness=2;p2.foreground=5;
-    rep=[t0,y0,-1];
-    while rep(3)==-1 then
-      rep=xgetmouse();
-      t0=rep(1); y0=rep(2);
-      if (tmin<t0 & t0<tmax & ymin<y0 & y0<ymax) & (abs(t0-oldt0)>=dt | abs(y0-oldy0)>=dy) then
-        t1=t0:0.1:tmax;
-        [sol1,rd]=ode("root",y0,t0,t1,1.d-2,1.d-4,f,2,g);
-        t2=t0:-0.1:tmin;
-        [sol2,rd]=ode("root",y0,t0,t2,1.d-2,1.d-4,f,2,g);
-        p1.data=[t1(1:size(sol1,"*"))' sol1'];
-        p2.data=[t2(1:size(sol2,"*"))' sol2'];
-        oldt0=t0; oldy0=y0;
+      p2=gce();p2.thickness=2;p2.foreground=5;
+      rep=[t0,y0,-1];
+      while rep(3)==-1 then
+        rep=xgetmouse();
+        t0=rep(1); y0=rep(2);
+        if (tmin<t0 & t0<tmax & ymin<y0 & y0<ymax) & (abs(t0-oldt0)>=dt | abs(y0-oldy0)>=dy) then
+          t1=t0:0.1:tmax;
+          [sol1,rd]=ode("root",y0,t0,t1,1.d-2,1.d-4,f,2,g);
+          t2=t0:-0.1:tmin;
+          [sol2,rd]=ode("root",y0,t0,t2,1.d-2,1.d-4,f,2,g);
+          p1.data=[t1(1:size(sol1,"*"))' sol1'];
+          p2.data=[t2(1:size(sol2,"*"))' sol2'];
+          oldt0=t0; oldy0=y0;
+        end
       end
     end
   end
-end
-lines(oldln(1))
+  lines(oldln(1))
+endfunction
+
+demo_ode_1dvect();
+clear demo_ode_1dvect;
index 0f8860d..998f5f6 100644 (file)
@@ -5,38 +5,48 @@
 
 // Equation definition
 
-function r=chemres(t,y,yd)
-   r(1)=-0.04*y(1)+1d4*y(2)*y(3)-yd(1);
-   r(2)=0.04*y(1)-1d4*y(2)*y(3)-3d7*y(2)*y(2)-yd(2)
-   r(3)=y(1)+y(2)+y(3)-1;
-endfunction
+function demo_ode_chimpl()
+
+  function r=chemres(t,y,yd)
+     r(1)=-0.04*y(1)+1d4*y(2)*y(3)-yd(1);
+     r(2)=0.04*y(1)-1d4*y(2)*y(3)-3d7*y(2)*y(2)-yd(2)
+     r(3)=y(1)+y(2)+y(3)-1;
+  endfunction
 
 
-function p=chemad(t,y,p),p=p+diag([1 1 0]),endfunction
+  function p=chemad(t,y,p),p=p+diag([1 1 0]),endfunction
 
-function p=chemjac(t,y,yd)
-  p=[-0.04,     1.d4*y(3)      ,  1.d4*y(2);
+  function p=chemjac(t,y,yd)
+    p=[-0.04,     1.d4*y(3)      ,  1.d4*y(2);
       0.04, -1d4*y(3)-6d7*y(2) , -1d4*y(2);
       1   ,     1              ,  1       ]
+  endfunction
+
+  // Integration
+
+  y0   = [1;0;0];
+  yd0  = [-0.04;0.04;0];
+  t    = [1.d-5:0.02:.4 0.41:.1:4 40 400 4000 40000 4d5 4d6 4d7 4d8 4d9 4d10];
+  rtol = 1d-4;atol=[1.d-6;1.d-10;1.d-6];
+  y    = impl(y0,yd0,0,t,rtol,atol,chemres,chemad,chemjac);
+
+  // visualization
+
+  my_handle = scf(100001);
+  clf(my_handle,"reset");
+  demo_viewCode("ode_chimpl.dem.sce");
+
+  drawlater()
+  plot2d(t',(diag([1 10000 1])*y)',style=(1:3))
+  ax=gca();
+  ax.log_flags = "lnn";
+  ax.box="on";
+  ax.margins(4)=0.2;
+  title(_("chemical process (implicit)"))
+  l=legend(['y1';'10^4 y2';'y3']);l.legend_location = "lower_caption"
+  drawnow()
+  
 endfunction
 
-// Integration
-
-y0   = [1;0;0];
-yd0  = [-0.04;0.04;0];
-t    = [1.d-5:0.02:.4 0.41:.1:4 40 400 4000 40000 4d5 4d6 4d7 4d8 4d9 4d10];
-rtol = 1d-4;atol=[1.d-6;1.d-10;1.d-6];
-y    = impl(y0,yd0,0,t,rtol,atol,chemres,chemad,chemjac);
-
-// visualization
-
-my_handle = scf(100001);
-clf(my_handle,"reset");
-demo_viewCode("ode_chimpl.dem.sce");
-
-drawlater()
-plot2d(t',(diag([1 10000 1])*y)',style=(1:3))
-ax=gca();ax.log_flags = "lnn";ax.box="on";ax.margins(4)=0.2;
-title(_("chemical process (implicit)"))
-l=legend(['y1';'10^4 y2';'y3']);l.legend_location = "lower_caption"
-drawnow()
+demo_ode_chimpl();
+clear demo_ode_chimpl;
\ No newline at end of file
index e55e67f..dad3579 100644 (file)
@@ -5,51 +5,57 @@
 
 //chemical process (stiff)
 
-// Equations definition
-deff("[yd]=chem(t,y)",[
+function demo_ode_chstiff()
+
+  // Equations definition
+  deff("[yd]=chem(t,y)",[
      "yd(1)=-0.04*y(1) + 1d4*y(2)*y(3);";
      "yd(3)= 3d7*y(2)*y(2);";
      "yd(2)= -yd(1) - yd(3);"])
 
-// finding points such that y1=1.e-4 or y3=1.e-2
+  // finding points such that y1=1.e-4 or y3=1.e-2
 
-// Integration
-t     = [1.d-5:0.02:.4 0.41:.1:4 40 400 4000 40000 4d5 4d6 4d7 4d8 4d9 4d10];
-rtol  = 1.d-4;atol=[1.d-6;1.d-10;1.d-6];
-y     = ode([1;0;0],0,t,rtol,atol,chem);
+  // Integration
+  t     = [1.d-5:0.02:.4 0.41:.1:4 40 400 4000 40000 4d5 4d6 4d7 4d8 4d9 4d10];
+  rtol  = 1.d-4;atol=[1.d-6;1.d-10;1.d-6];
+  y     = ode([1;0;0],0,t,rtol,atol,chem);
 
-// Visualisation
+  // Visualisation
 
-my_handle = scf(100001);
-clf(my_handle,"reset");
-demo_viewCode("ode_chstiff.dem.sce");
+  my_handle = scf(100001);
+  clf(my_handle,"reset");
+  demo_viewCode("ode_chstiff.dem.sce");
 
-drawlater()
-plot2d(t',(diag([1 10000 1])*y)',style=(1:3))
-ax=gca();ax.log_flags = "lnn";ax.box="on";ax.margins(4)=0.2;
-title(_("chemical process (implicit)"))
-l=legend(['y1';'10^4 y2';'y3']);l.legend_location = "lower_caption"
-drawnow()
+  drawlater()
+  plot2d(t',(diag([1 10000 1])*y)',style=(1:3))
+  ax=gca();ax.log_flags = "lnn";ax.box="on";ax.margins(4)=0.2;
+  title(_("chemical process (implicit)"))
+  l=legend(['y1';'10^4 y2';'y3']);l.legend_location = "lower_caption"
+  drawnow()
 
-messagebox("Click Ok to continue.","modal");
+  messagebox("Click Ok to continue.","modal");
 
-// Add surface condition
-nt = prod(size(t));
-deff('[y]=Surf(t,x)','y=[x(1)-1.e-4;x(3)-1.e-2]');
+  // Add surface condition
+  nt = prod(size(t));
+  deff('[y]=Surf(t,x)','y=[x(1)-1.e-4;x(3)-1.e-2]');
 
-// First root
-[y,rd,w,iw] = ode("root",[1;0;0],0,t,rtol,atol,chem,2,Surf);rd;
+  // First root
+  [y,rd,w,iw] = ode("root",[1;0;0],0,t,rtol,atol,chem,2,Surf);rd;
 
-while rd<>[] then
+  while rd<>[] then
   
-  [nw,ny]=size(y);
-  k=find(rd(1)>t(1:nt-1)&rd(1)<t(2:nt));
-  
-  // Visualisation
-  write(%io(2),[rd(1);y(:,ny)]','(''t='',e10.3,'' y='',3(e10.3,'',''))');
-  plot2d1("oln",rd(1)',(diag([1 10000 1])*y(:,ny))',style=[-3,-3,-3]);
+    [nw,ny]=size(y);
+    k=find(rd(1)>t(1:nt-1)&rd(1)<t(2:nt));
+    
+    // Visualisation
+    //write(%io(2),[rd(1);y(:,ny)]','(''t='',e10.3,'' y='',3(e10.3,'',''))');
+    plot2d1("oln",rd(1)',(diag([1 10000 1])*y(:,ny))',style=[-3,-3,-3]);
   
-  // Next root
-  [y,rd,w,iw]=ode('root',[1;0;0],rd(1),t(k+1:nt),rtol,atol,chem,2,Surf,w,iw);
-  
-end
+    // Next root
+    [y,rd,w,iw]=ode('root',[1;0;0],rd(1),t(k+1:nt),rtol,atol,chem,2,Surf,w,iw);
+  end
+
+endfunction
+
+demo_ode_chstiff();
+clear demo_ode_chstiff;
index b146057..d0a7f22 100644 (file)
@@ -5,59 +5,78 @@
 
 // ODE definition
 
-function ydot=lorenz(t,y)
-    x    = y(1);
-    a    = [-10,10,0;28,-1,-x;0,x,-8/3];
-    ydot = a*y
-endfunction
+function demo_ode_lorentz()
 
-function j=jacobian(t,y)
-    x  = y(1);
-    yy = y(2);
-    z  = y(3);
-    j  = [-10,10,0;28-z,-1,-x;-yy,x,-8/3]
-endfunction
+  function ydot=lorenz(t,y)
+      x    = y(1);
+      a    = [-10,10,0;28,-1,-x;0,x,-8/3];
+      ydot = a*y
+  endfunction
 
-// Integration
+  function j=jacobian(t,y)
+      x  = y(1);
+      yy = y(2);
+      z  = y(3);
+      j  = [-10,10,0;28-z,-1,-x;-yy,x,-8/3]
+  endfunction
 
-y0       = [-3;-6;12];
-t0       = 0;
-step     = 0.01;
-t1       = 10;
-instants = t0:step:t1;
-y        = ode(y0,t0,instants,lorenz,jacobian);
+  // Integration
 
-// Visualization - animation
+  y0       = [-3;-6;12];
+  t0       = 0;
+  step     = 0.01;
+  t1       = 10;
+  instants = t0:step:t1;
+  y        = ode(y0,t0,instants,lorenz,jacobian);
 
-my_handle = scf(100001);
-clf(my_handle,"reset");
-demo_viewCode("ode_lorentz.dem.sce");
-title(_("Lorentz differential equation"))
+  // Visualization - animation
 
-function h = poly3d(x,y,z)
-  xpoly(x,y);h=gce();h.data(:,3)=z
+  my_handle = scf(100001);
+  clf(my_handle,"reset");
+  demo_viewCode("ode_lorentz.dem.sce");
+  title(_("Lorentz differential equation"))
+
+  function h = poly3d(x,y,z)
+    xpoly(x,y);h=gce();h.data(:,3)=z
+  endfunction
+  
+  curAxe = gca();
+  
+  drawlater()
+  curAxe                 = gca();
+  curAxe.view            = '3d'
+  curAxe.axes_visible    = 'on'
+  curAxe.data_bounds     = [min(y,'c')';max(y,'c')']
+  curAxe.margins(3)      = 0.2;
+  curAxe.title.text      = [_("Lorenz differential equation")
+                  "dy1/dt = -10*y1 + 10*y2"
+                  "dy2/dt =  28*y1 -    y2 -  y1*y3"
+                  "dy3/dt =          y1*y2 - 8/3*y3"
+                  ]
+  curAxe.grid            = curAxe.hidden_axis_color*ones(1,3);
+  curAxe.x_label.text    = 'y1'
+  curAxe.y_label.text    = 'y2'
+  curAxe.z_label.text    = 'y3'
+  
+  //the trace
+  p = poly3d(y(1,1),y(2,1),y(3,1));
+  drawnow()
+  
+  //Animate
+  for k=1:size(y,2)
+  
+    if ~is_handle_valid(my_handle) then
+      break;
+    end
+  
+    if is_handle_valid(p) then
+      p.data=[p.data;
+        y(1:3,k)'];
+