Question

In: Computer Science

Project on a double pendulum using MATLAB. I have simulated double pendulum chaos using the code...

Project on a double pendulum using MATLAB. I have simulated double pendulum chaos using the code I found in Chegg. Could you please guide in adding a code to determine the time it takes for the second arm of the pendulum to "flip" based on initial starting conditions?

Solutions

Expert Solution

clc %---------------------------------------------------------------------------------------------------%

clear % function:Animates the comparison of two double pendulum's with almost similar initial parameters %

% parameters: %

% th1(1) : the angle of the top mass of the first double pendulum %

% th2(1) : the angle of the bottom mass of the first double pendulum %

dt=0.01; % thd1(1): the speed of the top mass of the first double pendulum %

T=10; % thd2(1): the speed of the bottom mass of the first double pendulum %

N=int16(T/dt); % al1(1) : the angle of the top mass of the second double pendulum %

th1=zeros(N,1); % al2(1) : the angle of the bottom mass of the second double pendulum %

al1=zeros; % ald1(1): the speed of the top mass of the second double pendulum %

th2=zeros(N,1); % ald2(1): the speed of the bottom mass of the second double pendulum %

al2=zeros(N,1); % ___________________________________________________ %

thd1=zeros(N,1);

ald1=zeros(N,1);

thd2=zeros(N,1);

ald2=zeros(N,1);

thdd1=zeros(N,1);

aldd1=zeros(N,1);

thdd2=zeros(N,1);

aldd2=zeros(N,1);

X1=zeros(N,1);

Y1=zeros(N,1);

Z1=zeros(N,1);

D1=zeros(N,1);

X2=zeros(N,1);

Y2=zeros(N,1);

Z2=zeros(N,1);

D2=zeros(N,1);

figure;

hold off;

th1(1)=pi/2;

al1(1)=pi/2;

th2(1)=pi+0.02; %---------------------------------------------------------------------------------------------------%

al2(1)=pi;

thd1(1)=0;

ald1(1)=0;

thd2(1)=0;

ald2(1)=0;

g=10;

A=-2*g*sin(th1(1))-sin(th1(1)-th2(1))*thd2(1)^2;

J=-2*g*sin(al1(1))-sin(al1(1)-al2(1))*ald2(1)^2;

B=-g*sin(th2(1))+sin(th1(1)-th2(1))*thd1(1)^2;

K=-g*sin(al2(1))+sin(al1(1)-al2(1))*ald1(1)^2;

thdd1(1)=(A-B*cos(th1(1)-th2(1)))/(2-(cos(th1(1)-th2(1)))^2);

aldd1(1)=(A-B*cos(al1(1)-al2(1)))/(2-(cos(al1(1)-al2(1)))^2);

thdd2(1)=B-cos(th1(1)-th2(1))*thdd1(1);

aldd2(1)=B-cos(al1(1)-al2(1))*aldd1(1);

X1(1)=sin(th1(1));

Y1(1)=cos(th1(1));

D1(1)=sin(al1(1));

Z1(1)=cos(al1(1));

X2(1)=sin(th1(1))+sin(th2(1));

Y2(1)=cos(th1(1))+cos(th2(1));

D2(1)=sin(al1(1))+sin(al2(1));

Z2(1)=cos(al1(1))+cos(al2(1));

for i=2:N

thd1(i)=thd1(i-1)+dt*thdd1(i-1);

ald1(i)=ald1(i-1)+dt*aldd1(i-1);

thd2(i)=thd2(i-1)+dt*thdd2(i-1);

ald2(i)=ald2(i-1)+dt*aldd2(i-1);

th1(i)=th1(i-1)+dt*thd1(i);

al1(i)=al1(i-1)+dt*ald1(i);

th2(i)=th2(i-1)+dt*thd2(i);

al2(i)=al2(i-1)+dt*ald2(i);

A=-2*g*sin(th1(i))-sin(th1(i)-th2(i))*thd2(i)^2;

J=-2*g*sin(al1(i))-sin(al1(i)-al2(i))*ald2(i)^2;

B=-g*sin(th2(i))+sin(th1(i)-th2(i))*thd1(i)^2;

K=-g*sin(al2(i))+sin(al1(i)-al2(i))*ald1(i)^2;

thdd1(i)=(A-B*cos(th1(i)-th2(i)))/(2-(cos(th1(i)-th2(i)))^2);

aldd1(i)=(J-K*cos(al1(i)-al2(i)))/(2-(cos(al1(i)-al2(i)))^2);

thdd2(i)=B-cos(th1(i)-th2(i))*thdd1(i);

aldd2(i)=K-cos(al1(i)-al2(i))*aldd1(i);

X1(i)=sin(th1(i));

D1(i)=sin(al1(i));

Y1(i)=cos(th1(i));

Z1(i)=cos(al1(i));

X2(i)=sin(th1(i))+sin(th2(i));

D2(i)=sin(al1(i))+sin(al2(i));

Y2(i)=cos(th1(i))+cos(th2(i));

Z2(i)=cos(al1(i))+cos(al2(i));

plot([0, X1(i), X2(i)], [0, -Y1(i), -Y2(i)],'-o');

hold on

plot([0, D1(i), D2(i)], [0, -Z1(i), -Z2(i)],'-o');

axis([-2 2 -2 2]);

title(['t = ', num2str(double(i)*dt, '% 5.3f'), ' s']);

hold on

plot(X2(1:i), -Y2(1:i), 'r');

plot(D2(1:i), -Z2(1:i), 'g');

hold off

drawnow;

end


Related Solutions

I need an original matlab code and gui for a simple double pendulum. This needs to...
I need an original matlab code and gui for a simple double pendulum. This needs to be original and not too complicated. Please provide basic instructions. Thank you!
Using Matlab code, solve the following: (a) Consider first the undamped pendulum ? + sin ?...
Using Matlab code, solve the following: (a) Consider first the undamped pendulum ? + sin ? = 0, ?(0) = 0, ? (0) = b. Let x = ? and y = ? ; then x and y satisfy the system x = y y = ? sin x, x(0) = 0 y(0) = b. Solve this system numerically and plot, on a single graph, the resulting trajectories for the initial velocities b = 0.5, 1, 1.5, 2, 2.5. Use...
Matlab code problems I have to write a code using functions to find out if a...
Matlab code problems I have to write a code using functions to find out if a year is a leap year. I'm on the write track i feel like but I keep getting an error message and matlab isnt helping to troubleshoot. The issue is on line 30. Here is my code: function project_7_mfp() %   PROJECT_7_ABC   project_7_abc() creates a function that prompts the user %   enter a year after 1582 It then determines if it is a leap year %...
I'm new in MATLAB and I have to write a code in MATLAB which converts a...
I'm new in MATLAB and I have to write a code in MATLAB which converts a number from one base to another without using base2base, etc
I want the code for the 2D Ising model using Matlab
I want the code for the 2D Ising model using Matlab
I am trying to do edge detection using matlab. I have posted code here. It does...
I am trying to do edge detection using matlab. I have posted code here. It does not give any error but it's not running it at all. So please help me to fix it and also exaplin each line of this code pls. Thanks! i = imread('C:\Users\Amanda\Desktop"); I = rgb2gray(1i); BW1 = edge(I,'prewitt'); BW2= edge(I,'sobel'); BW3= edge(I,'roberts'); subplot (2,2,1); imshow(I); title('original'); subplot(2,2,2); imshow(BW1); title('Prewitt'); subplot(2,2,3); imshow(BW2); title('Sobel'); subplot(2,2,4); imshow(BW3); title('Roberts');
Hello, I need the Matlab code of the Fourier Transform without using the Matlab functions fft...
Hello, I need the Matlab code of the Fourier Transform without using the Matlab functions fft and dft. Applied to discrete signals. If you can with an example.Thank you!!
Determine the output using C++ of the following code fragment i) double *pt; double a[3] =...
Determine the output using C++ of the following code fragment i) double *pt; double a[3] = {1.2, 2.3, 3.4}; pt = &a[1]; pt += 1; cout << *pt << endl; ii) int i = 1; while (i <= 4) { int num = 1; for (int j = 1; j <= i; j++) { cout << num << "bb"; num *= 3; } cout << endl; i++; }
For a catapult project I must make a MATLAB code that should make use of the...
For a catapult project I must make a MATLAB code that should make use of the projectile motion equations so for a given input range R (horizontal distance from the catapult to the target), the code outputs the necessary velocity and firing angle of the catapult. What is the code for this? I am lost.
For a catapult project I must make a MATLAB code that should make use of the...
For a catapult project I must make a MATLAB code that should make use of the projectile motion equations so for a given input range R (horizontal distance from the catapult to the target), the code outputs the necessary velocity and firing angle of the catapult. I must be able to input ranges: 7ft, 8ft and 9ft and the output of the code should give me the possible velocities and theta of the catapult.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT