Andri Yadi

A geeky technopreneur, trying to do something big with his startup

What is The Weirdest Thing You Do Using Excel?

Another event, another presentation and demo, but still about VSTO. Yesterday, I delivered a talk about VSTO on an event entitled "Weekend with MUGI Seminar" at University of Pasundan (UNPAD), on March 15, 2009. This time, I opened my presentation with a question "What is the Weirdest Thing You Do using Microsoft Excel?". Unfortunately, no audiences answered the question. I expected somebody will raise hand and mention something wild/weird that he/she do using Excel or Office product.

To show the audience the uncommon thing that can be done using Excel, I did a demo to simulate pendulum motion. Before I talk about the demo, let's squeeze some brains to understand how the simulation can be made.

The illustration of pendulum motion:


To be able to simulate the motion, all you need to have is the motion equation. More specifically, you need to know how amplitude (theta) change with time. Let's see how we can get the equation.
Force diagram of simple gravity pendulum is


Some mathematical derivations:
 


Under the initial conditions θ(0) = θ0 and dθ/dt(0) = 0, the solution of differential equation is



And the period is



By knowing initial theta (θ0) and string/rod length (l), I can simulate the motion. Here's the screenshot:

At the left side, we have the simulation. At the middle, there're some input fields. And at the right side, there's a chart plotting the theta against the time. As we see, the chart is sinusoidal means the motion is Simple Harmonic Motion.

The crowd applause when the pendulum start to swing...

The main part of code is:

                double thetaT = theta0;
           
            do {
                t += dt;

                thetaT = theta * Math.Cos(t * Math.Sqrt(9.8/(stringLength/100)));

                pendulumY = stringLength * Math.Cos(thetaT);
                pendulumX = stringLength * Math.Sin(thetaT);

                pendulum.Top = platformBelow +
                               Convert.ToSingle(pendulumY);
                pendulum.Left = referenceLeft +
                                Convert.ToSingle(pendulumX) - (pendulum.Width / 2);

                System.Windows.Forms.Application.DoEvents();

            } while (true);


Where:
  • theta0: initial theta
  • thetaT: theta at a time t
  • stringLenght: String/Rod length
  • platformBelow: the position (from the top of the screen) of platform where string/rod hangs
  • referenceLeft: the position (from the left of the screen) of reference/equilibrium line
That looping will go forever, so you need to create code to stop it.

To get the full source code, just grab the code and presentation slide at: http://dycode.com/files/folders/mugi/entry189.aspx

And here're some photos during the event:






That's it. Enjoy.



Share this post: | | | |
Published Mar 16 2009, 05:24 PM by andriyadi
Filed under: , ,

Comments

 

Dicky Arinal said:

This is abolutely weird, physics simulation running on top of excel? What do you expect from this kind of app? Anyway, cool presentation I thought.

Indeed, I was once presented physics simulation using C++, on front of UI physics student. Because of this post, I become 'itch' to share the event.

Btw, kok link-nya nggak bisa diunduh mas? :)

March 16, 2009 11:56 PM
 

andriyadi said:

@Dicky

Why Excel?

- Simpler programming than C++. isn't it?

- To prove you can do much more using Excel. Not only business-related stuffs

- Every body knows Excel. So for novice users, they don't have to adapt when it come to use the simulation.

- We did use Excel to do simple simulation in Physics, ITB. My lecturer taught me, only he used VBA/Macro to do it.

I admit, it's not possible to do simulation in realtime using Excel. However, for simple simulation, I think it's enough.

Anyway, thanks for the comment.

March 17, 2009 4:55 AM
 

go2ismail said:

mantap!!! fisika pisan!!! yang ngajarin siapa ndri? pak zakki?

March 17, 2009 7:02 AM
 

andriyadi said:

@Ismail:

Yang ngajar pak Beni, kuliah Kapita Selekta Komputasi. Lu emang gak ngambil dulu?

March 18, 2009 2:31 AM
 

mybrainsgrowell said:

link donloadnya kok ndak bisa di unduh ya??

March 18, 2009 5:59 AM
 

andriyadi said:

@mybrainsgrowell:

Udah bisa diunduh sekarang. Sorry salah link

March 28, 2009 6:16 AM