Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help Programming this in VBA for Excel Below is the document I have to work with. I have no idea where to even

I need help Programming this in VBA for Excel

Below is the document I have to work with. I have no idea where to even start.

Example 3-7

This example extends Newtons method from your Calculus I class to a real-world orbital mechanics problem. It uses the method to solve Kepler's Equation. Kepler's equation is not one of Kepler's three laws. Kepler's equation relates the satellite's angular position to the time. It's a very common calculation and I imagine that at this instant there are hundreds of computers solving this equation hundreds of times per second. That is because this equation allows you to estimate where a satellite will be in a given (small) amount of time. We are constantly tracking thousands of satellites and Kepler's equation is one of the formulas that can be used to support that tracking.

Unfortunately (or fortunately, as my advisor used to say!) we cannot solve Kepler's equation by hand. It is what math people call transcendental. Here it is: n t = E - e sin (E) Big E and little e are not the same thing. Little e is the eccentricity of the satellite's orbit, a measure of how circular, e = 0, or flattened, e close to 1, the ellipse is. Big E is called the eccentric anomaly and it is shown on the picture above. The satellite's orbit is the black ellipse and the orange circle has radius a, where a is the semi-major axis of the ellipse. The angle from the horizontal axis to the satellite, through the earth, is the true anomaly, Greek letter nu. The two anomalies are not the same but they can be related to each other. n is the mean motion of the satellite. It gives the average angular velocity of the satellite around the earth, so the satellite's period is two*pi divided by n. t is the time that has passed since perigee, the place where the satellite is closest to the earth. The product of n and t is denoted M, the mean anomaly. Using this Kepler's equation becomes: M = E - e sin (E) Here's the problem statement: Given the orbit of the satellite, find the location of the satellite a given time t after perigee. To do this we need to solve Kepler's Equation. We would know M and e and all we would have to do is solve for E, one equation with one unknown. Piece of cake, right?! Think about it, you'll see there is no way to do it by hand. One simple way to solve this problem numerically is with Newton's method. I've included an explanation of Newton's method and a flowchart of the method on another page. In Newton's method, we are solving the problem f(x) = 0. That might not look like our problem but actually all we have to do is put the M on the other side of the equation: f(E) = E - e sin (E) - M Now all we have to do is find the right E by iteration! Newton's method does require the first derivative of f(E) with respect to E: f_prime(E) = 1 - e cos (E) Now we're ready. Here's the program that solves Kepler's Equation given the mean anomaly and the eccentricity. Notice how I use the simple DO loop with three different exit statements.

(C++ Program supplied below) **Note: I NEED TO PROGRAM THIS IN VBA

#include #include #include using namespace std; int main(int argc, char *argv[]) { //*** This program performs Newton's method to find the solution to //*** a transcendental equation. //*** The equation is M = EA - e sin(EA), known as Kepler's equation. //*** M is the mean anomaly, EA is the Eccentric anomaly and e is the //*** eccentricity of the orbit. //*** M and e are inputs. EA is an output. // Programmer: Ima Engineer double M ; // The mean anomaly double EA; // The eccentric anomaly double e ; // The eccentricity double F ; // The function that is supposed to be zero double FP; // The derivative of F with respect to EA bool CONVERGED = false; bool DIVERGED = false; double TOL; int ITERATIONS; const int MAX_ITERATIONS = 10; // Always after 10 iterations const double MAX_EA = 1.0E12; // Stop if EA exceeds this number. cout << "Enter the mean anomaly in radians:"; cin >> M; cout << "Enter the eccentricity:"; cin >> e; while (e < 0 || e > 1.0) { cout << "Eccentricity is a number between zero and one." << endl; cout << "Enter the eccentricity:"; cin >> e; }; // end of the while loop cout <<"Enter the tolerance (e.g. 10E-8):"; cin >> TOL; EA = M; // Set the first guess for EA equal to M ITERATIONS = 0; // Don"t do this as part of the declaration. Why not? F = EA - e * sin(EA) - M; // Evaluate function do { if (ITERATIONS == MAX_ITERATIONS) break; // Check for too many iterations if (abs(EA) > MAX_EA) // Check for divergence { DIVERGED = true; break; }; if (abs(F) < TOL) // Check for convergence { CONVERGED = true; break; }; FP = 1 - e * cos(EA); // Evaluate derivative of function EA = EA - F / FP; // Calculate new EA F = EA - e * sin(EA) - M; // Evaluate function ITERATIONS++; cout <

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

More Books

Students also viewed these Databases questions