Here's a cool pulley simulation I made visualised on Matlab:
I'm learning to animate simulations on Matlab. So, I decided to animate one of my coolest problems, Simulating Dynamics-2
The actual simulation was done with the help of Karan Chatrath's code solution to my problem. I modified the code to make it more efficient and added some extra features, and more importantly writing the second part of the code, which was animating the data.
The setup above is basically two masses connected by a pulley, with the second mass dragging the first mass with the help of gravity. There is friction between the first mass and the floor.
The equations of motion can be derived using Newton's Laws, here's the system in matrix form:
We can solve for these values simply by multiplying the inverse system matrix by the vector on the right hand side. Once we do this, we have to numerically integrate x¨,y¨, the first and second indices of the solution to A−1b.
For the animation, just draw two squares with the tops at the position of the point masses at x coordinate for the first mass x and y coordinate for the second mass y. Then draw lines from the hinge to each mass.
To maintain accuracy, I added a counter to add the values of time, x, and (y) to arrays. The animation works by while looping through these arrays, drawing the data, deleting the data, and redrawing through the loops.
The values I used for the simulation are m1=3,m2=2,g=10,μ=0.8,l=14m
clear all;close all;clc;%% Initialisation and constantsdeltaT=10^-5;time=0;m1=3;m2=2;g = 10;mu=0.8;x=-14*cos(asin(8/14));y=0;xDot=0;yDot=0;massPosition1=[];massPosition2=[];times=[];count=0;%% SimulationwhilexDot>=0 if mod(count, 1000) == 0times=[times;time];massPosition1=[massPosition1;x];massPosition2=[massPosition2;y]; end%System matrixA=[m10mu-x/(y-14);0 m2 0 1;0 0 1 (1 - x^2/(y - 14)^2)^(1/2);2*x28-2*y00];%Vectorb=[0;m2*g;m1*g;2*yDot^2-2*xDot^2];%Solution vector (accelerations, tension, and normal force)S=inv(A)*b;xDotDot=S(1);yDotDot=S(2);%Numerical IntegrationxDot=xDot+xDotDot*deltaT;yDot=yDot+yDotDot*deltaT; x = x + xDot*deltaT; y = y + yDot*deltaT;%Updating time and countertime=time+deltaT;count=count+1;end%% Plotaxis(gca,"equal");O=[00];Hinge=[0.28];axis([-121.5-19]);grid on;%% Animationi=1;while i <= length(times)%animation speed control conditional statement if mod(i,5) == 0%Hinge circlehingeCircle=viscircles(Hinge,0.2);%timetitle("time: "+num2str(ceil(times(i)))+" s");%Positions and string line plottingMass_1=rectangle('Position',[(massPosition1(i)-0.5)-111]);stringToHinge1=line([massPosition1(i)Hinge(1)-0.15],[0Hinge(2)+0.2]);Mass_2=rectangle('Position',[0(7-massPosition2(i))11]);stringToHinge2=line([0.40.4],[8(8-massPosition2(i))]);%pausing for animationpause(10^-6);%Deleting previous elements to draw new ones in next iteration if i < length(times)-5delete(Mass_1);delete(stringToHinge1);delete(Mass_2);delete(stringToHinge2); endend%looping through arraysi=i+1;end%% End
Have a try for yourself, or, if you don't have Matlab, take a look at the GIF above.
This discussion board is a place to discuss our Daily Challenges and the math and science
related to those challenges. Explanations are more than just a solution — they should
explain the steps and thinking strategies that you used to obtain the solution. Comments
should further the discussion of math and science.
When posting on Brilliant:
Use the emojis to react to an explanation, whether you're congratulating a job well done , or just really confused .
Ask specific questions about the challenge or the steps in somebody's explanation. Well-posed questions can add a lot to the discussion, but posting "I don't understand!" doesn't help anyone.
Try to contribute something new to the discussion, whether it is an extension, generalization or other idea related to the challenge.
Stay on topic — we're all here to learn more about math and science, not to hear about your favorite get-rich-quick scheme or current world events.
Markdown
Appears as
*italics* or _italics_
italics
**bold** or __bold__
bold
- bulleted - list
bulleted
list
1. numbered 2. list
numbered
list
Note: you must add a full line of space before and after lists for them to show up correctly
Easy Math Editor
This discussion board is a place to discuss our Daily Challenges and the math and science related to those challenges. Explanations are more than just a solution — they should explain the steps and thinking strategies that you used to obtain the solution. Comments should further the discussion of math and science.
When posting on Brilliant:
*italics*
or_italics_
**bold**
or__bold__
paragraph 1
paragraph 2
[example link](https://brilliant.org)
> This is a quote
\(
...\)
or\[
...\]
to ensure proper formatting.2 \times 3
2^{34}
a_{i-1}
\frac{2}{3}
\sqrt{2}
\sum_{i=1}^3
\sin \theta
\boxed{123}
Comments
@Percy Jackson
@NSCS 747
In case you're interested. I couldn't get Karan Chatrath or Steven Chase's tag though lol.
@Talulah Riley If you're active anymore.
Log in to reply
Nice bro! Your mentions are all wrong. I didn't get the notif as they're not blue. I can mention them for you though - @NSCS 747, @Talulah Riley, @Karan Chatrath, @Steven Chase
Log in to reply
Yeah; I may have edited the comment. When you edit comments, all your mentions go away. Btw thanks a lot for adding them back :)
Log in to reply
Impressive work
Log in to reply
Thanks. Seeing it visualised adds a level of cool to simulations.