” PHY336语言编程 辅导、c/c++程序 写作Homework 1; due on Tuesday, March 16PHY336, Computational Physics, Spring 2021Department of Physics, SUSTech1. MONTE CARLO INTEGRATIONA sphere of radius r1 consists of two different materials, with densities 1 and 2. The materialwith density 2 is located within a cylinder of radius r2, as illustrated in Fig. 1, and the materialof density 1 fills up the rest of the sphere. Write a program that calculates the two momentsof inertia of this sphere corresponding to rotation about the z and x axis. The inner cylinder iscentered around the z-axis, as also shown in the figure.Figure 1: A solid sphere of radius r1 with an inner solid cylinder of radius r2. The cylinder consistsof a material with density 2; the rest of the sphere consists of a material with density 1.Carry out the calculation using Monte Carlo sampling of the moment of inertia integral, (1)where r(x, y, z) is the perpendicular distance of the point (x, y, z) from the axis of rotation (herethe x or z axis, giving Ix and Iz). Enclose the sphere in a box with side L = 2r1 in order toeasily do the calculation using (x, y, z) points. Use the 64-bit linear congruential random-numbergenerator that you tested in homework assignment 1 (reading the seed integer from a file seed.in),with the factor included to Convert the integers to double-precision numbers in the range [0, 1) (thegenerator with this factor included is available on the course web site).The program should read the following input from a file read.in:r1,r2,rho1,rho2,npt,nbi1where r1,r2 are the two radii (in m), rho1,rho2 are the densities (in kg/m3), npt is the number ofrandom points generated per bin (for which bin averages are computed) and nbi is the numberof bins (on the basis of which the final average and statistical error are computed).Bin averages should be computed for both the Iz and Ix moments of inertia and these should bewriten to a file bin.dat containing nbi lines, each with the bin number followed by the Iz and Ixvalues (write these averages to the file after each bin is completed; it is not necessary to store thedata in the program). The final average and error bar (standard deviation of the mean) computedusing the bin averages should Be written to a file res.dat.As a specific case, do the calculation for a copper (8930 kg/m3) sphere of radius 5 cm with an innergold (19320 kg/m3) cylinder of radius 1 cm. Use 106 points per bin (npt) and do the calculationfor nbi=50,500,5000. For the final case, construct a histogram of the bin averages (with the widthof the histogram bins chosen in a reasonable way to get of the order tens of histogram bins withsignificant weight). The report on this problem needs to contain only the final numerical results(averages and standard deviations) For the three runs and the histogram for the last run. Commenton the shape of the histogram.22. Calculate the volume of a d (d=2,3,4) dimensional sphere of radius r=1 using MonteCarlo (MC). Give an average value and an error estimate as a function of MC points.如有需要,请加QQ:99515681 或WX:codehelp
“
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。