lundi 19 septembre 2022

Having trouble understanding two questions

The first one is:

● Write a C++ program to estimate PI using the numerical integration method. Your program should ask the user to input the total number of rectangles n that are used to estimate the area of a quarter of the circle with radius r = 1. ● Define PI = 3.14159265 and report your error when you use n = 10, 10^2, 10^3 and 10^4 rectangles. Please include your error calculation inside your code, and output the estimated PI(10 digits after the decimal point) and error(5 digits after the decimal point) at the same time. ● error = [(estimated_PI – true_PI) / true_PI] * 100% EX: if the input is: 10 the output is: 3 The estimated value of pi is 3.3045184612 with n=10. The error is 5.18609%

and the second one is:

● Write a C++ program to estimate PI using the Monte Carlo method. ● Your program should ask the user to input the total number of random points (xi, yi) we will generate in the simulation. Use “srand(time(0))” function ● Define PI = 3.14159265. Estimate PI value(10 digits of precision) and the error(5 digits of precision) when you use 10^3 ,10^4, 10^5 and 10^6 samples. ● error = [(estimated_PI – true_PI) / true_PI] * 100% ● After you find the value of Pi, use that to find the area of an ellipse5 digits of precision) with semi-major axis as 10 and semi minor-axis of 7, and report the “estimated PI value”, “error”, “estimated ellipse area” simultaneously. ● Hint: Ellipse area = πab ● Your answer might not be exactly the same as the output below due to randomness. EX: if the input is: 1000 the output is: The estimated value of pi is 3.1119999886 with n=1000. The error is -0.94197% The estimated ellipse area is 217.84000

Could someone please walk me through these problems or in some way help me to understand them?

Aucun commentaire:

Enregistrer un commentaire