[Solved] CPP Assignment 3

30 $

File Name: CPP_Assignment_3.zip
File Size: 150.72 KB

SKU: [Solved] CPP Assignment 3 Category: Tag:

Or Upload Your Assignment Here:


This part of the assignment is due by the 9/12.In general always write your name and date of creation as comments in the files andtry to be “user friendly” when you write the code:● Add comments on the code to remember yourself and the other whatthe code does● Manage the possible errors in the input given by the userThe 70% of this assignment consists in completing part 1) (a,b and c, e )1. Define a class that includes the cauchy function and members to calculate theintegral of the function and sample random points on it.a. Define the function, with a constructor that takes as argument the extremes ofthe linear dominion where the function is defined and a string. These 3 thingsshould initialize private member of the class.b. Define a private member function that is the cauchy function: f(x)= 1π(1+x2)c. Define a public member function of the class that evaluates the integral of thefunction, on the range stored as private members. The integral can becalculated as I= R*( N ) where xi are random points extracted from theΣ (xi)Nifrange and R is the length of the range. The integral should be 0.874 if youuse -5,5 as extremes of the range.d. Add a member function that sample random numbers from the Cauchydistribution. To sample random number from a not-uniform distribution youcan use the Metropolis algorithm.i. Generate a random number (x) on the range where the function isdefined, sampled from a uniform function. This will be the first numberyou generated (x 1 =x)ii. Iterative:1. Generate a random number y from the uniform distribution2. Compute A=min( f(y) , ) , where f is the function and x t is thef(xt) 1previous number extracted3. Accept y with probability A.4. If you accepted y x t+1 = y otherwise x t+1 =x t5. Write x t+1 on a file, called as the string that you passed asargument to the constructore. Write a separate file where you have your maini. Build an object of your new classii. Call the function that calculates the integral ( you could pass as onlyargument of the function the number of points)iii. Call the metropolis algorithm member function( you could pass as onlyargument of the function the number of points). This should create afileiv. You can include in your main file cauchy_test.h: #include“cauchy_test.h” and compile also adding cauchy_test.cc to the g++list, then call in your main CreateHistogramFile(outputfile,low,high),where outputfile is the file created in point 3 and low and high are theranges given to the constructor. This will create a file calledinput_plotting.csv that you can open with excel/gnuplot to check if yougenerated points according to a Cauchy distribution

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CPP Assignment 3
30 $