Physics 281: Computational Physics, Spring 2019 Activities for Meetings 16-17, Tues-Thurs 3/26-28/191
留学生物理代写 Write a program to that uses odeint to find Vout(t) at the same set of time points. Use the initial condition Vout(0) = 0.0 V.
- Newman Ch. 8: Ordinary differentialequations:
-1 First-order differential equations with one variable.
-2Differential equations with more than one variable.
-3 Second-order differentialequations. 留学生物理代写
These three sections cover the material we will use in P281. You should take a look at the remaining sections of Ch. 8 to get an idea of some more advanced methods for solving ODEs.
- Section “Solving ordinary differential equations” in handout Summary of numerical methods.
In-Class Activities 留学生物理代写
Completing all of the non-starred activities will count as A-level work. To receive credit, these activities must be checked off in class or office hours within three weeks (by Fri 4/19).
1.Solving an ODE with odeint: The low-pass filter.
The circuit shownin the figure below built from a resistor R and a capacitor C is called a “low-pass filter”. The input voltage Vin(t) is specified. Then the output voltage Vout(t) is determined by the following first-order ODE:
This is called a low-pass filter because low-frequency sine waves with angular frequencies ω 1/RC pass through this circuit nearly un- changed, while high frequency sine waves with ω 1/RC are (imper- fectly) blocked. For this problem use R = 10 kΩ, C = 1 µF which gives 1/RC = 100 rad/s.
12019-03-27 P281 W9ab.tex §c 2019 Donald Candela
(a)Assume Vin(t) = A sin(ωt) with A = 2.0 V and ω = 50 rad/s. 留学生物理代写
Write a program that defines a function to compute Vin(t) and uses this function to make a plot of Vin(t) for 0 < t < tmax, with tmaxchosen to show about two or three complete cycles of the sine Make the number of time points a variable that you can easily change it (or input the number of points when you run your program. Start with several hundred points to get a nice smooth curve.
(b)Write a program to that uses odeint to find Vout(t) at the same set of time points. Use the initial condition Vout(0) = 0.0 V. Plot Vin(t) and Vout(t) on the same graph (with labeled axes and a legend for the two curves, of course). Because ω < 1/RC,the output should be only a little bit smaller than the input and slightly shifted in phase.
(c)Runyour program again, changing ω to 300 rad/s. Now the out- put should be quite a bit smaller than the input, and shifted in phase by nearly π/ For both values of ω you should find that Vout(t) is a sine wave except for an initial transient near t = 0.
2.Euler’s method. 留学生物理代写
Add code to your program to compute Vout(t) at thesame set of time points using Euler’s method, and plot the results on the same graph as the odeint Find the minimum number of time points for which the Euler’s-method results appear identical (by eye) to the odeint results. (For this purpose, you may want to remove the Vin(t) curve from your plot.)
3.Add code to compute Vout(t) using the second-order Runge- Kutta method, and plot the RK2, Euler’s-method, and odeint results together.As with the previous activity, find the minimum number of time points for which the RK2 results appear identical (by eye) to the odeint results. 留学生物理代写
4.*RK4. As explained in Newman Sec. 8.1.3, if you didn’t have an ODE integrator like integrate.odeint and had to program one yourself, you would probably use fourth-order Runge-Kutta, which isquite accurate. Modify your program from the last activity to include an RK4 integration of the ODE, using the formulas from Newman Sec. 8.1.3. To check the accuracy, have your program print out y(tmax)for the various methods (odeint, RK2, RK4).