Please turn in this assignment (and all future assignments for this course) by emailing them to me . Please use the subject of "Physics 222 HW2" for these assignments (if you use the link above, the subject will be added automatically). Please attach the any source code to programs that you write for this assignment. If you write more than one program, attach each separately. When answering the questions themselves feel free to answer directly in the body of your message (or attach your answers). I may take off points for assignments that are not sent to me in the correct form.
Write a
e = lim (1 + 1/n)n
n → ∞to find approximations for the mathematical constant e. Your function should take as input a long double precision number, and return an approximate value for e as a long double precision number. Be careful about the types that you use for numbers in this program. Your main program should ask for the user to input a number that you will pass to your function for it to use as n in the formula above for calculating e. Your program should compare your approximation for e to the value that you get by calculating:e1. You can do so using the exp function. Note to use this function, you must have an
#include <cmath>line near the top of your program. To use this function include a line something like:
cout << exp(1.0L) << '\n';This will give exp a long double version of 1.0, which will give you a fairly precise value for e. Also, calculate and print out the percent error in your calculation of e. Note that you also need to use the pow(x,y) function which calculates xy.
Test your program with the following input: 1., 10., 100., 1000., 10.6, 10.9 and 10.12. Send your results in with your assignment. Comment on your results.
Use the cout.precision(j) command to force cout to show j digits. Use this function before the places where you are going to print out results to force the program to show you enough digits so that you can tell the accuracy of your program. 8 or 10 digits will probably be sufficient.
Write a program which find the peak wavelength in the light emitted by a blackbody. A blackbody is an ideal object that is both a perfect emitter and a perfect absorber of light. (See section 38.8 Continous Spectra, p.1334-1337, in University Physics by Young and Freeman, a similar text, or Wikipedia for more details.) The spectrum of light from follows the form of the Plank radiation law:
I(λ) = 2πhc2/(λ5(ehc/λkT - 1))where I(λ) is emittance, λ is wavelength, h is Plank's constant, c is the speed of light, and T is the temperature.
Plank's radiation law gives the amount of light emitted as a function of the temperature the object and the wavelength of the light. Plots of Plank's radiation law give curves which peak at wavelength's given by Wien's law:
λm = b/Twhere λm is the wavelength at which the maximum amount of light is emitted, T is the absolute temperature, and b is a constant which is 2.8977685 x 10-3 K*m in SI units. For this problem it will be most convenient if you use temperature in Kelvin (K), wavelengths in nm, and b = 2.8977685 x 106 K*nm.
Your program should have a function that will take a temperature in Kelvin and return a wavelength in nm. The main function of your program should call the calculation function with the input list below.
#include <plstream.h>You will also need to define all of the numeric variables that you use with the plot as types PLFLT and PLINT, in place of float and int. You will also need corresponding lines like the rest of the example. To compile your program, you should add:
`pkg-config --cflags --libs plplotd-c++`to the end of your usual compiling command. PLPlot allows you to choose from many different forms of output. While developing your program you should probably choose <11> wxwidget or <11> xwin. For your final postscript plot output you should choose <3> ps or hit the save file button from the wxwidget window.
Curren;y, PLPlot is installed on nx.csbsju.edu, the computer that NX logs you into, and the computer lab Linux boxes. So you should not need to do this anymore.
To use ssh, open up a terminal window as you would usually do. Then within that window type ssh -Y machine_name, where you replace machine_name with the name of the computer that you want to log into. Available machines include lincartns140, lincartpe225, lincartpe229, lincartpe244, and lincartpe248. The -Y tells ssh that you may want to open new windows from within your ssh session. So for example:
ssh -Y lincartpe244would log you into lincartpe244.
Once you are logged in, you can compile and run programs as normal.