代写Session 7 activities worksheet帮做C/C++编程

Session 7 activities worksheet

Due: February 14                         Regrades until: March 20

Online listings: eigen_basis_class.cpp and diffeq_oscillations.cpp printouts.

Now that we've got routines to solve differential equations, we're going to explore some interesting ones: nonlinear oscillators. Today we'll play with a program that solves for the time dependence of such an oscillator.
Your goals for today (and ...):

· If you didn't complete it, do the plot from Session 6 of relative error at t=1 vs. mesh size h.

· Think about how to enhance the eigen_basis code with more C++ classes.

· Run a code that solves the differential equation for a (driven) nonlinear oscillator and explore how the time dependence changes as various input parameters change.

· Add friction (damping) to the code.

A) More on C++ Classes: eigen_basis_class

The code eigen_basis_class.cpp is a simple modification of eigen_basis.cpp to use the Hamiltonian class we introduced for eigen_tridiagonal_class.cpp. Here we'll take a few minutes to think about how to introduce additional classes.

1. Take a look at the eigen_basis_class.cpp printout and note how the Hamiltonian class is re-used without modification. (If you haven't done so yet, read the discussion of this class in the Session 7 notes.) The only tricky change is that matrix indices go from 1 to dimension rather than from 0 to dimension-1. What parts of the Hamiltonian class implementation do you not yet understand? 

2. The potential is another good candidate for a class. We'd like to just evaluate the potential at r without having to use constructions like the switch statement in the Hij_integrand function with all the messy void parameters. (Think about how awkward and prone to error it is to add another potential.) What would you like the declaration statement (the one where the Potential object is declared in the main program) for the Potential class to look like? What method(s) would you like the class to have? 

3. Give at least one example of an additional class that would be useful to define. 

B) Driven Nonlinear Oscillations

The Session 7 notes describe the driven nonlinear oscillator that is coded in diffeq_oscillations.cpp. Note that the force depends on k and an exponent p, the external force has a magnitude f_ext, a frequency w_ext, and a phase phi_ext. The initial conditions in position and velocity are designated x0 and v0. You also have control over the time interval (increase t_end to see longer times), the step size h, and how often points are printed to the file (plot_skip).

1. Use make_diffeq_oscillations to create diffeq_oscillations. This code outputs to the file diffeq_oscillations.dat five columns of data: t, x(t), v(t), kinetic energy, and potential energy. There are four gnuplot plot files provided (diffeq_oscillations1.plt, etc.), each of which generates a different type of plot. Run diffeq_oscillations with the default values (enter "0" when it says "What do you want to change?") to calculate a data set. Start gnuplot and "load diffeq_oscillations1.plt" and then "load diffeq_oscillations2.plt". (Once you've given these commands once, you can use just use the arrows to go back and forth.) Briefly, what do each of these plots show? 

2. Wouldn't it be convenient to generate all four plots at once in separate files? Load "diffeq_oscillations_all.plt"! (Check the warning in the file on what to do if you get an "unknown or ambiguous terminal type" error message!)

3. It's always a question whether or not you have coded a problem correctly, so you should always seek ways to check your results. One possibility is if we have a known solution. This works for p=2 (simple harmonic oscillator). What about other p? Another check is to identify a quantity that shouldn't change with time. Create a plot of such a quantity (you'll want to increase t_end) and observe the effect of changing the step size h to a larger value [e.g., try 10 and 100 times larger]. How do you decide on a reasonable h to use? 
(The "plot_skip" parameter indicates how often a point is written to the output file. So plot_skip=10 means that every 10 points is output.)

4. Verify that different amplitudes (e.g., different initial conditions determined by x0 and v0) lead to different periods for an anharmonic oscillator (p≠2). [Hint: You might find the "append" option useful.] Can you identify a qualitative rule? E.g., does larger amplitude mean shorter or longer period always? Try to explain the rule? Make sure you try different values of p, since they might lead to different rules! 

5. Go back to the original parameters (quit the program and start it again), which has p=2. Now add a driving force f_ext=10 with w_ext=1 and look at the time dependence and phase-space plots. Then increase w_ext to 3.14 and then to w_ext=6.28. What are you observing? Now repeat with p=3 (starting with f=0). Can you find resonant behavior? 

C) Adding Damping

Real-world systems have friction, which means the motion will be damped. The Session 7 notes have a list of three simple models for friction. We'll implement viscous damping: Ff = -b*v, where v(t) is the velocity.

1. Introduce the damping parameter "b" into the code: 

1. add it to the force_parameters structure (with a comment!);

2. add it to the list of local force parameters in the main program;

3. give it an initial value;

4. add a menu item (e.g., [13]) and a case statement to get a new value.

Try this part out before proceeding. Did it work? 

2. Modify the "rhs" routine to include damping (you're on your own here!). What did you add? 

3. Test your routine starting with p=2 and a small damping and look at both the time dependence and the phase-space plots. Then try some other p values.

4. Identify the three regimes described in the Session 7 notes: underdamped, critically damped, and overdamped.

D) EXTRA: Looking for Chaos (Part I)

Now we want to put it all together: a damped, driven, nonlinear oscillator. A different system with the same basic features is the realistic pendulum, which is described in the Session 7 notes.

1. In the notes there is a list of characteristic structures that can be found in phase space, with sample pictures. Can you find a combination of parameters for the non-linear oscillator that produce a pictures like the chaotic one in the notes? Provide the parameters you used and include a phase space plot. Make sure to set t_end to something large (e.g., 400), so that you are not only looking at transients. Also make sure to think about the necessary conditions for chaos when selecting your parameters and to turn on some damping (without that you will see transients forever).

E) Reflection

Write down which of the six learning goals on the syllabus this worksheet addressed for you and how:

 

 


热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图