Difference between revisions of "Нелинейные колебания груза с вынуждающей силой"

From Department of Theoretical and Applied Mechanics
Jump to: navigation, search
Line 98: Line 98:
 
     var startX = 0;      // fixing of a spring
 
     var startX = 0;      // fixing of a spring
  
     // создаем прямоугольник-грузик
+
     // create a rectangle=
 
     var rect = {
 
     var rect = {
 
         x: x0,  width: rw,
 
         x: x0,  width: rw,
Line 105: Line 105:
 
     };
 
     };
  
     // захват прямоугольника мышью
+
     // capture a rectangle with the mouse
     var mx_;                                    // буфер позиции мыши (для расчета скорости при отпускании шара)
+
     var mx_;                                    // position buffer of a mouse
     document.onmousedown = function(e) {        // функция при нажатии клавиши мыши
+
     document.onmousedown = function(e) {        // function when pressing a key of a mouse
         var m = mouseCoords(e);                // получаем расчетные координаты курсора мыши
+
         var m = mouseCoords(e);                // receive settlement coordinates of the cursor of a mouse
  
 
         var x = rect.x;
 
         var x = rect.x;

Revision as of 22:14, 31 May 2016

thumb|Nonlinear Oscillations of cargo with the driving force|500px

Annotation to the project

In this project we study the nonlinear oscillations of the load acting on it with a periodic force

Statement of the problem

Let suspended on a non-linear spring load mass m experiences the external force F, the change in law F = sin (t)

  • write a program in JavaScript, simulating the behavior of the load when setting various parameters of the system..

General information about the subject

If the oscillatory system is affected by periodically changing external force, then the system makes fluctuations which nature to some extent repeats nature of change of this force. Such fluctuations are called compelled.

F0 is called the amplitude of the force which is also the highest value of force.

Thanks to the work carried out by an external force, increasing the maximum values, which reach the potential energy of the spring and the kinetic energy of the load. Loss to overcome the resistance forces will increase. Finally, the moment will come when the work of the external force will exactly offset the energy losses in the system. Further increase of fluctuations in system will stop, and fluctuations with some constant amplitude will be established. ||
Характер амплитуды


equation of motion: [math]m\ddot x = -kx -{k_1}x^3 + {F_0}sin(t) - B \dot x[/math]

Visualization in JavaScript

Download program: SpringNoLine.rar

'

Файл "Spring.js" <syntaxhighlight lang="javascript" enclose="div">

   window.addEventListener("load", Main_Spring, true);
   function Main_Spring() {
   var canvas = spring_canvas;
   canvas.onselectstart = function () {return false;};     // ban selection canvas
   var ctx = canvas.getContext("2d");                      // drawing on ctx
   var w = canvas.width;                                   // width of the window in the calculated coordinates
   var h = canvas.height;                                  // the height of the window in the calculated coordinates
   var Pi = 3.1415926;    	      	                    // "Pi"
   var m0 = 1;    		      	                    // weight scale
   var T0 = 1;    		      	                    // time scale(period of fluctuations of initial system)
   var t = 0;
   var k0 = 2 * Pi / T0;           	                    // frequency scale
   var C0 = m0 * k0 * k0;          	                    // hardness scale
   var B0 = 2 * m0 * k0;  	      	                    // viscosity scale
   var omega = 10;
   
   // *** physical parameters ***
   var F = 80;
   var m = 1 * m0;                 	                    // mass
   var C = 1 * C0;                 	                    // rigidity
   var C1 = 1 * C0;                 	                    // rigidity1
   var B = .1 * B0;                 	                    // viscosity
   
   slider_m.value = (m / m0).toFixed(1); number_m.value = (m / m0).toFixed(1);
   slider_C.value = (C / C0).toFixed(1); number_C.value = (C / C0).toFixed(1);
   slider_C1.value = (C / C0).toFixed(1); number_C1.value = (C / C0).toFixed(1);
   slider_B.value = (B / B0).toFixed(1); number_B.value = (B / B0).toFixed(1);
   slider_F.value = (F / 40).toFixed(1); number_F.value = (F / 40).toFixed(1);
   // *** computing parameters***
   var fps = 300;		      	            // frames per second 
   var spf = 100;		      	            // steps per frame   
   var dt  = 0.05 * T0 / fps;    	            // integration step
   var steps = 0;                                  // number of integration steps
   function setM(new_m) {m = new_m * m0;}
   function setC(new_C) {C = new_C * C0;}
   function setC1(new_C1) {C1 = new_C1 * C0 * 0.067;}
   function setB(new_B) {B = new_B * B0;}
   function setF(new_F) {F = new_F * 40;}
   slider_m.oninput = function() {number_m.value = slider_m.value;       setM(slider_m.value);};
   number_m.oninput = function() {slider_m.value = number_m.value;       setM(number_m.value);};
   slider_C.oninput = function() {number_C.value = slider_C.value;       setC(slider_C.value);};
   number_C.oninput = function() {slider_C.value = number_C.value;       setC(number_C.value);};
   slider_C1.oninput = function() {number_C1.value = slider_C1.value;       setC1(slider_C1.value);};
   number_C1.oninput = function() {slider_C1.value = number_C1.value;       setC1(number_C1.value);};
   slider_B.oninput = function() {number_B.value = slider_B.value;       setB(slider_B.value);};
   number_B.oninput = function() {slider_B.value = number_B.value;       setB(number_B.value);};
   slider_F.oninput = function() {number_F.value = slider_F.value;       setF(slider_F.value);};
   number_F.oninput = function() {slider_F.value = number_F.value;       setF(number_F.value);};
   var count = true;                   // whether to carry out calculation of system
   var v = 0;				// body speed
   var rw = canvas.width / 30;    	
   var rh = canvas.height / 1.5;
   var x0 = 15 * rw - rw / 2;     	
   var y0 = rh / 1.33 - rh / 2;
   // spring parameters
   var coil = 10;        // number of turns
   var startX = 0;       // fixing of a spring
   //  create a rectangle=
   var rect = {
       x: x0,  width: rw,
       y: y0,	height: rh,
       fill: "rgba(0, 0, 255, 1)"    	// цвет
   };
   // capture a rectangle with the mouse
   var mx_;                                    // position buffer of a mouse
   document.onmousedown = function(e) {        // function when pressing a key of a mouse
       var m = mouseCoords(e);                 // receive settlement coordinates of the cursor of a mouse
       var x = rect.x;
       var xw = rect.x + rect.width;
       var y = rect.y;
       var yh = rect.y + rect.height;
       if (x <= m.x && xw >= m.x   && y <= m.y && yh >= m.y) {
           if (e.which == 1) {                         // нажата левая клавиша мыши
               rect.xPlus = rect.x - m.x;              // сдвиг курсора относительно грузика по x
               rect.yPlus = rect.y - m.y;              // сдвиг курсора относительно грузика по y
               mx_ = m.x;
               count = false;
               document.onmousemove = mouseMove;       // пока клавиша нажата - работает функция перемещения
           }
       }
   };
   document.onmouseup = function(e) {          // функция при отпускании клавиши мыши
       document.onmousemove = null;              // когда клавиша отпущена - функции перемещения нету
       count = true;
   };
   function mouseMove(e) {                     // функция при перемещении мыши, работает только с зажатой ЛКМ
       var m = mouseCoords(e);                 // получаем расчетные координаты курсора мыши
       rect.x = m.x + rect.xPlus;

// v = 6.0 * (m.x - mx_) / dt / fps; // сохранение инерции

       v = 0;
       mx_ = m.x;
   }
   function mouseCoords(e) {                   // функция возвращает расчетные координаты курсора мыши
       var m = [];
       var rect = canvas.getBoundingClientRect();
       m.x = (e.clientX - rect.left);
       m.y = (e.clientY - rect.top);
       return m;
   }
   // график
   var vGraph = new TM_graph(                  // определить график
       "#vGraph",                              // на html-элементе #vGraph
       250,                                    // сколько шагов по оси "x" отображается
       -1, 1, 0.2);                            // мин. значение оси Y, макс. значение оси Y, шаг по оси Y
   function control() {
       calculate();
       draw();
       requestAnimationFrame(control);
   }
   control();

// setInterval(control, 1000 / fps); // Запуск системы

   function calculate() {
       if (!count) return;
       for (var s=1; s<=spf; s++) {
           var f = -B*v - C * (rect.x - x0) - C1*Math.pow(rect.x - x0,3)+2*F*Math.sin(t);

v += f / m * dt; //console.log(f);

           rect.x += v * dt;

t+= dt;

           steps++;
           if (steps % 80 == 0) vGraph.graphIter(steps, (rect.x-x0)/canvas.width*2);   // подать данные на график
       }
   }
   function draw() {
       ctx.clearRect(0, 0, w, h);

draw_spring(startX, rect.x, h/2, 10, 50);

       ctx.fillStyle = "#0000ff";
       ctx.fillRect(rect.x, rect.y, rect.width, rect.height);
   }


function draw_spring(x_start, x_end, y, n, h) { ctx.lineWidth = 2;

       ctx.strokeStyle = "#7394cb";

var L = x_end - x_start; for (var i = 0; i < n; i++) { var x_st = x_start + L / n * i; var x_end = x_start + L / n * (i + 1); var l = x_end - x_st; ctx.beginPath(); ctx.bezierCurveTo(x_st, y, x_st + l / 4, y + h, x_st + l / 2, y); ctx.bezierCurveTo(x_st + l / 2, y, x_st + 3 * l / 4, y - h, x_st + l, y); ctx.stroke(); } }

}