Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.25 KB | None | 0 0
  1. function [T, U] = beam()
  2. %BEAM Resolves the differential equation of a spring attached a beam
  3. %   Returns the angle the beam makes with the vertical, and the angular
  4. %   speed for 100 time-steps between 0 and 15.
  5. %   Detailed explanation of the problem can be found in this document:
  6. %   http://perso.uclouvain.be/vincent.legat/teaching/bac-q3/data/probleme-problem1415-5.pdf
  7. %   (in french)
  8.  
  9. Tstart = 0;
  10. Tend   = 15;
  11.  
  12. n = 1000; % Nombre de pas de temps
  13. h = (Tend-Tstart)/n; % Taille d'un interval
  14. T = linspace(Tstart,Tend,n+1); % Chaque pas de temps t
  15. U = zeros(n+1,2); % Contient (theta theta') pour chaque temps t
  16.  
  17. % Condition initiale: quand t = 0
  18. U(1, 1) = 0; % Theta = 0
  19. U(1, 2) = 0; % Theta' = 0
  20.  
  21. % Application de Runge-Kutta d'ordre 4 sur chaque pas temps t
  22. for i=1:n
  23.     K1 = f(T(i),     U(i,:)        );
  24.     K2 = f(T(i)+h/2, U(i,:)+h*K1/2 );
  25.     K3 = f(T(i)+h/2, U(i,:)+h*K2/2 );
  26.     K4 = f(T(i)+h,   U(i,:)+h*K3   );
  27.     U(i+1,:) = U(i,:) + h*(K1+2*K2+2*K3+K4)/6;
  28. end
  29.  
  30. end
  31.  
  32.  
  33. function dudx = f(t,u)
  34. dudx = u;
  35.  
  36. % Constante du problème
  37. L = 1; % [m]
  38. k = 140; % [N/m]
  39. C = 10; % [Nms]
  40. m = 10; % [kg]
  41. g = 9.81; % [m/s^2]
  42.  
  43. sinTheta = sin(u(1));
  44.  
  45. dudx(1) = u(2);
  46. dudx(2) = (L*(0.1-sinTheta*k*L) + m*g*L*sinTheta - C*u(2)) / (m*(2*L)^2/3);
  47. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement