Eth: 0x00cce8E2e56a543abc084920eee3f88eFD0921ea

Monday, February 13, 2012

Modeling Gravity with Matlab

It seemed a bit cumbersome to organize all this code and information on a blog so I've move to the Spaceience Website hosted by google. I also put some more explanations in there on the simpler to implement models (non-ODE45).

Today there are some amazingly neat computer programs that can allow students at the high school and college level to easily extend what they have learned in the classroom to real applications. However, it's not as if you're teachers will walk you through this, they have better things to do! Today I'll walk you through creating a very simple gravity simulator in Matlab using the basic equations of gravitational attraction that you know and adding in a little Matlab coding to make it dance. We will only be using the sun and the earth in this first model but it can easily be extended to include whatever planets you like.

What You Need
The only thing you'll need to do this project is
  • a student copy of Matlab 2007 or better 
  • access to Wikipedia to look up terms you might have forgotten
  • access to Matlab documentation to help you construct your program

Review the System Information
Matlab is a very smart program. If you tell it the position, velocity and acceleration of a particle, it can predict where that particle will end up. A similar example is if we were in a car at a stop light and as soon as the light turned green we would start constantly accelerating at 5 m/s^2, you could calculate our position in ten seconds. In this case, our initial position at the stoplight is our x position =0. Our initial velocity is also = 0 since we start from a stop. Our constant acceleration, however, is = 5 m/s^2. For the Earth/Sun system, we can easily find the position and velocity of the Earth at any point in it's orbit. The acceleration is the hard part since it is constantly changing. If we can find a general expression for the acceleration, we can give the position, velocity and acceleration to Matlab and Matlab will do that calculation you did to find the cars position a thousand times over in the blink of an eye. It has to do the calculation lots of times because the acceleration is changing based on the position of Earth.
 First thing we want to do before coding up a model in matlab is to understand the basic equations at work. Starting from the first principles of Newton's Laws governing gravitational attraction we want to understand the acceleration of the Earth as it goes around the sun.
From Wikipedia: Gravitational Constant
 Starting from this principle, we will focus on finding the acceleration of the Earth.
This is telling us that the force gravity exerts is equal to the universal gravitational constant times the mass of of the first object, times the mass of the second object, divided by the radius between them squared. For our purposes we will set G=1.4879*10^(-34) in units of AU^3/(kg*Day^2). The reasons for these units is because we want it to work easily with the initial position and velocity data we will acquire from the JPL ephemeris database.

Force can also be expressed as . Combining these two equations we find the following:


Similarly for the Sun we can say:

So we have found an expression for the acceleration of the sun and the acceleration of Earth. For this simple model we will assume that the amount of movement that the sun experiences from earth is so small it basically stays still. This means we will neglect the acceleration of the sun from our calculations which will make life much simpler. As always, you can add this in later.
Note: Mass sun is a constant, G is a constant, R is NOT a constant

Position and Velocity Data from JPL
JPL keeps a database of the predicted position and velocity of every cataloged object in our solar system. This includes asteroids! We need to select a date, and search the database to tell us our initial conditions which will later be put into Matlab. Go to the JPL HORIZONS web-interface. We only need to find the inial position of the earth for the date specified. This is because we are assuming the sun is at [0,0,0] and has no acceleration or velocity. Make sure the ephemeris type is Vectors. The target body should be Earth (Geocenter) as opposed to the Earth-Moon barycenter which is the center of the Earth-Moon system. We will use a start date of February 12, 2012. A step size of 10 days will give us the position on the 12th and the 22nd.

JPL HORIZONS Web-Interface



Then we click generate and we get the following data:

The data we will use is highlighted in green. Make sure to read the table at the top of the Ephemeris to make sure you understand what the units are. For our example, in the green box, the top row is the [X,Y,Z] position of Earth in AU. The second row below that is the [Vx,Vy,Vz] velocities of Earth in AU/Day.

Build it in Matlab
Lets review the information we've collected:
  • Sun - position, velocity, acceleration all assumed to be zero
  • Earth - position and velocity from JPL, have a function for acceleration in terms of radius
Now that we have all our starting information we can build the Matlab simulator. Open up Matlab and create a new script file saved as "SimpleGravity.m". In this we will build our program. We will need to also build a separate function in another script file. Create a new script file and save it as "Propagator.m". SimpleGravity will call Propagator when we run it.

Components of SimpleGravity.m
  •  Input the time over which we'd like to see the simulation run as well as the size of the time step we would like to use. A smaller time step means more processing is required.
  • Create some global variables
  • Input initial conditions for the Sun from our assumptions [0,0,0] position, [0,0,0] velocity
  • Input initial conditions for the Earth from JPL
  • Call the process ODE45 on the function Propagator.m function
  • Plot the results


Components of Propagator.m


This part is where you'll need to look up some Matlab functions and familiarize yourself with Matlab programming. I could walk you through every function call but that wouldn't be exciting. I have included a pdf document detailing the final result of each of the above steps. However, I suggest that you try to write it up yourself first. It's ok if you don't know how the ODE45 command works, just try and get the basic commands down before using the cheat sheet. ODE45 takes your current position, velocity and acceleration and calculates what your next position and velocity will be at some timestep later specified by you. (It uses a Runge-Kutta method for you math geeks). Matlab is wonderfully useful for all sorts of calculations. If you're an engineering student, I really suggest you take the time to really learn and understand this program.





Matlab Code
SimpleGravity.m
Propagator.m 

Make sure that you put them in the same directory and execute SimpleGravity.m. Change the result by making the step size smaller or increasing the number of days the final time.

Check your Answer
If you want to check how well your simulator works, set finaltime to 10 days. Look at the last line of finalposition, the first three numbers represent the last x,y,z position of Earth. Compare this against the position given by JPL from our initial data show in the picture above.

Feedback
Send Feedback Please! Hope you have been inspired.


Sunday, February 12, 2012

Understanding Environmental Impact as a Child

Once upon a time there was a Dragon
And there were no people and there were no trees
The Dragon at all the trees and cows
Then he died in his cave.
 .
 .
.
The End


This is a story I dictated and illustrated when I was five or six years old and still in preschool. Proof that even children are smart enough to know that when you consume too much it can only lead to disaster.



Monday, October 31, 2011

Beacon Power Bankrupted by Regulations

Beacon Power is a good example of a company going bankrupt due to interference by regulators. Beacon received a $45 million loan from the federal government. Meanwhile, regulatory agencies slashed the prices that Beacon could demand for their services and effectively squeezed the company dry:
As a regulated industry, utilities were only allowed to pay a fixed rate set by government regulators for Beacon's services, the DOE said. The rate was not high enough for the company to survive. (source)
This is a clear demonstration that regulators do not know what is best for the energy market. The hidden cost of "low prices" and "rate regulation" is that companies margins are cut to the point that operations no longer bring in profits. At that point, it is more effective to close up shop and move to a different industry than it is to keep working in the same industry.

I say to you utilities regulators: Fie! Fie! Fie! Let the market decide what the price should be. The road to more expensive power is paved with your maladroit regulations. Sure you may push prices down in the short run with regulations, but when those companies go out of business as Beacon Power has, prices will go up.

Friday, October 7, 2011

Drag Effects in Low Earth Orbit

Designing spacecraft to survive low earth orbit is a challenge. Atomic oxygen is attempting to dissolve the leading surface of the craft, sunlight is pumping heat into your satellite and the gravity gradient and magnetic fields are playing with your attitude control systems. Most exciting, however, is the fact that the neutral atmosphere which can reach up to 1200km altitude, it in a slow dance with your craft. The atmosphere that exists up at 300km altitude is not as thick as down here at sealevel, but your satellite is trying to pass through it at 7km/second. At those speeds, there are enough particles to seriously effect your satellite, slow it down, and drag it back down to earth. Not to mention during solar max, the number of particles increases by a factor of three or more! That's like, wooooah!

So what can we do about this? Slap a thruster to your satellite and have it boost you back up to the speed and altitude you want. "But how much energy will this really take?" you might wonder. I'll give you an example:

A satellite with 1m^2 of leading surface area traveling at 300km circular orbit around earth with an engine efficiency of 150 seconds would require something on the order of 34 kg per year to stay in orbit. "That's fantastic" you're thinking. "Only an extra 34kg and I'm good to go!" Slow down there cowboy, there's a bit more to it than that see, if you go 50km lower, you need 3x that amount of fuel (103kg), and if you go 50km higher, you need only x1/3 of that fuel (11kg). Not to mention, if you satellite is traveling around during a solar maximum (lots of solar radiation and particles) you'll need 3x the amount of fuel for all those orbits!

So now you're thinking, "OK so I orbit the earth at 250km which means i need 34x3kg fuel and then during a solar max I need 34x3x3 kg! That's crazy! I liked just having to use 34kg of fuel." Well life ain't that easy. I've included a graph which can help illuminate things.

This is showing you graphically what we just talked about. The baseline case is shown in blue. When there is more (or less) solar activity, it changes the amount of fuel required to stay in orbit. This is because increased solar activity heats up the atmosphere (a gas) which then expands. As it expands, it pushes the top layers further up. This means that at 300km the density of the neutral environment (think air) increases as there is more solar activity. Conversely, the density of the neutral environment decreases when there is less solar activity. This means that if you're lucky and you are flying during a solar min period, you don't need to store as much fuel on your satellite.

Wednesday, October 5, 2011

Lessons Learned from the US / EU Financial Crisis:

The most succinct summation of the breakdown of monetary logic following the financial crisis: 
That there is no price to be paid for spending money wastefully, no risk in lending to the reckless and no point in saving your money since it will be confiscated to pay for the folly of those who have not.
                             -James Whyte, philosopher and Senior Fellow fo the Cobden Centre and author of Crimes Against Logic. Posted on BBC news.


Sunday, September 11, 2011

DELab update for MatLab 7

Download DELab.zip (MatLab 7 Compatible) 

DELab is a GUI-based front end to M ATLAB that implements the analytic, graphical, and numerical tools used in the text Differential Equations: Modeling with MATLAB, Prentice Hall, 1999. Main Website

Save either file to a convenient directory (e.g., matlabr11/work/delab), unzip or unpack ("tar xf delab.tar") the file, add that directory to your MATLAB path using either the addpath command (type "help addpath" in the MATLAB command window) or the Path Browser (choose File/Set Path... from the MATLAB menu bar), and type "delab" in the MATLAB command window to start DELab.

DELab requires MATLAB 5.3 (Release 11) or higher.
Please send questions, comments or suggestions to Paul Davis at pwdavis@wpi.edu; put "DELab" in the subject line.

DELab is copyright 1999, 2000 by Paul Davis. It is for non-profit educational use only.

Wednesday, September 7, 2011

G1 USB Unable to Mount

I was having a problem whereby when I plugged my G1 into my Vista machine, it would not mount so I could not retrieve files or download pictures. I found this useful walkthrough which fixed the problem. Basically the problem is that the computer is mounting the device as an HTC dream as opposed to USB storage. Original Post here:

Finally, I got it work on my vista ultimate.

Here is what I do, hope it can help.

1. Just as lots of people mentioned, I did not see removable disk showing in Explorer after I connect G1 to computer. Even I tried mount on the phone, it still doesn't work.

2. Then I go to Device Manager, I don't even see any USB Mass Storage Device at all un Unversal Serial Bus controllers.

3. Because I know the device is connected, I decide to expand all the devices. Immediately, I notice there is a device called HTC dream.

4. We all know G1 is HTC and but it is recognized as HTC dream device rather than USB Mass Storage Device.

5. Now let's change it back to USB Mass Storage Device.

6. Right-Click on the device (HTC dream), select Update Driver Software (it is the first menu item).

7. Do not search automatically, click the second one (Browse my computer for driver software).

8. In next pare, choose Let me pick from a list of device drivers on my computer.

9. Now you will see two drivers are listed (select check box for Show compatible hardware)

10. Select USB Mass Storage Device and click Next.

11. After installing, now removable disk is shown in explorer.

12. When try to open the disk, it will ask you "Please insert a disk into Removable Disk".

13. Back to you phone, from notification bar, mount you sd from USB connected.

14. You can open to browse you SD card from your computer.