Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pendulum_period
- % pendulum waves-寻找合适的摆长
- clc;clear;close all
- g=10;T=200;
- opts=odeset('RelTol',1e-13,'AbsTol',1e-14, ...
- 'MaxStep',1e-3,'InitialStep',1e-4, ...
- 'Stats','off','Events',@(t,u)evns(t,u));
- L=0.8:0.01:2.4;
- for ii=1:length(L)
- [t,u]=ode45(@(t,u)pw(t,u,g,L(ii)), ...
- [0 T],[pi/6 0],opts);
- w(ii)=1/t(end);
- end
- max(w)
- min(w)
- L=interp1(w,L,1.28:0.05:2.18);
- save matlab.mat L
- %% 微分方程与事件函数
- function du=pw(~,u,g,L)
- du=[u(2);-g/L*sin(u(1))];
- function [position,isterminal,direction] = evns(~,u)
- position = u(1);isterminal = 1;direction = -1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement