Advertisement
Y-BH

N_pendulum_multi_data

May 8th, 2022
1,661
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.52 KB | None | 0 0
  1. clc;clear;close all
  2. load('func_N3k.mat')
  3. opts = odeset('RelTol',1e-13,'AbsTol',1e-16,'MaxStep',5e-3, ...
  4.     'InitialStep',1e-5,'Stats','on');
  5. T=100;fps=30;Frame=T*fps;
  6. t=linspace(0,T,Frame);
  7. M=100;
  8. x=zeros(Frame,N+1,M);y=x;
  9. tic
  10. for ii=1:M
  11. u0=[pi/2+zeros(N,1)-ii/M*1e-8;zeros(N,1)];
  12. [~,u] = ode89(@(t,u) eqns(t,u,N,f),t,u0,opts);
  13. for k=1:N
  14.     x(:,k+1,ii)=x(:,k,ii)+sin(u(:,k));
  15.     y(:,k+1,ii)=y(:,k,ii)-cos(u(:,k));
  16. end
  17. end
  18. toc
  19. function du=eqns(~,u,N,f)
  20. du=[u(N+1:2*N);
  21.     f(u(1:N))*([1;u(2*N:-1:N+1).^2])];
  22. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement