Advertisement
Y-BH

pendulum_period

Mar 26th, 2022
924
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function pendulum_period
  2. % pendulum waves-寻找合适的摆长
  3. clc;clear;close all
  4. g=10;T=200;
  5. opts=odeset('RelTol',1e-13,'AbsTol',1e-14, ...
  6.     'MaxStep',1e-3,'InitialStep',1e-4, ...
  7.     'Stats','off','Events',@(t,u)evns(t,u));
  8. L=0.8:0.01:2.4;
  9. for ii=1:length(L)
  10. [t,u]=ode45(@(t,u)pw(t,u,g,L(ii)), ...
  11.     [0 T],[pi/6 0],opts);
  12. w(ii)=1/t(end);
  13. end
  14. max(w)
  15. min(w)
  16. L=interp1(w,L,1.28:0.05:2.18);
  17. save matlab.mat L
  18. %% 微分方程与事件函数
  19. function du=pw(~,u,g,L)
  20. du=[u(2);-g/L*sin(u(1))];
  21. function [position,isterminal,direction] = evns(~,u)
  22. position = u(1);isterminal = 1;direction  = -1;
Advertisement
RAW Paste Data Copied
Advertisement