1. % The system parameters m=0.3; b=0.05; L=2; g=9.81; % For simplification r=g/L; k=b/(m*L); % The Pendulum ODE f = @(t
453 77 295KB
1. % The system parameters m=0.3; b=0.05; L=2; g=9.81; % For simplification r=g/L; k=b/(m*L); % The Pendulum ODE f = @(t,x) [x(2);-k*x(2)-r*sin(x(1))]; % Initial conditions init=[pi/2; 0]; % Solve ODE, The time interval is set from 0 to 10 seconds [t,x]= ode45(f,[0,50],init); % Plot the solution plot (t,x(:,1)); grid on; hold on; plot (t,x(:,2),'g'); xlabel('Time (s)'); ylabel('Amplitude'); legend({'Angle(rad)','Angular speed (rad/s)'});
2. function no2 a=0.01;h=100;k=63;r=5e-4;alpha=1.25;ro=16e-8;i=4; solinit = bvpinit(linspace(0,1,10),[40 0.5]); sol1 = bvp4c(@odefun,@bcfun,solinit); i=2; sol2 = bvp4c(@odefun,@bcfun,solinit); x = linspace(0,1); y1 = deval(sol1,x); y2 = deval(sol2,x); plot(x,y1(1,:),x,y2(1,:)); y1(1,100) y2(1,100) xlabel('Waktu (s)'); legend({'I=4 A','I=2 A'}); function dydx = odefun(x,y) dydx = [ y(2) 8*a^2*h/(k*r)*y(1)^alpha-4*a^2*ro*i^2/(k*pi^2*r^4)]; end function res = bcfun(ya,yb) res = [ ya(1) yb(2)]; end end