For this assignment you will write 3 routines, namely the Euler,Midpoint, and Eu
ID: 3608545 • Letter: F
Question
For this assignment you will write 3 routines, namely the Euler,Midpoint, and Euler-Cromer methods outlined in chapter 2.
Each one will call an external function named "a". "a"will take one arguement (the loop index), and will return areal/float. "a" here is the acceleration at that index. The routines will be named as follows:
euler(x,v,dt,n)
midpoint(x,v,dt,n)
eulercromer(x,v,dt,n)
Where x (possition) and v (velocity) are 1D arrays ofreal/floats, dt (time step) is a single real/float, and n is thenumber of steps to take.
Write in C++ the formulas for each equation is
Explanation / Answer
please rate - thanks sorry I can't code it because I don't understand the math. but I found this program which is virtually what you want, at http://www.twostonenet.com/business/progs/progs.html it's in C but that's simple enough to change #include #include int main() { int s; /* switch */ double gamma; double omega; double tend, dt, t; /* control parameter */ int nt; /* number of steps */ int i; /*loop control*/ void euler (double*, double*, double, double,double, double); void cromer (double*, double*, double, double,double, double); void midpoint (double*, double*, double, double,double, double); FILE *feuler; FILE *fcromer; FILE *fmidpoint; double x, v; /* calculatings */ printf(" *driven dumpedoscillator* "); printf(" Enter Omega: "); scanf("%le", &omega); printf("Enter Gamma: "); scanf("%le", &gamma); printf(" Enter the time forevaluation: "); scanf("%le", &tend); printf(" Enter the number ofintervals: "); scanf("%d", &nt); dt = tend / nt; /* determine dt */ tend = dt * nt; /* make sure, tend fits(rounding of dt) */ /* printf(" Enter desired method: (1)Euler (2) Euler-Cromer"); */ /* printf(" (3) Midpoint "); */ /* scanf("%d", &s); */ for (s=1; sRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.