\"Monte-Carlo\" Simulation is a technique commonly used in Engineering and Scien
ID: 3646137 • Letter: #
Question
"Monte-Carlo" Simulation is a technique commonly used in Engineering and Sciences to simulate random processes. We will attempt to use it to estimate the number "PI" ( pi ). The approach is to simulate the process of darts shot in a random fashion to a circular target drawn within a square frame. The premise is that if a large enough number of darts are thrown onto the target; the number of darts hitting within and outside a circular target will be proportional to the corresponding areas; i.e., # of darts within the circle Area of Circle = ( pi /4)D2 Total # of darts Area of Square Frame = D2 Then by calculating the ratio between the darts hitting the target and the total darts, we can estimate the number "pi" as # of darts within the circle/Total # of darts = pi (D2/4) Times (1/D2) = pi /4 Write a MATLA8 script that simulates "N" (where N is a user-defined "input") randomly shot darts to a square frame with a circular target drawn. Your script should differentiate between the darts hitting the circular area (target), and estimate the number "PI" as described above. "Series Approximation of Complex Functions" Expansion in series is a common approach used in Engineering to approximate trigonometric and other special functions. For instance, the trigonometric function "cos(x)" can be approximated by cos (X) = 1 - x2/2! + x4/4! - x6/6! + ...+ (-1)(N -1) X(2N - 2)/(2N - 2)! Write a MATLAB script "my cos.ni" that implements this approximation for the function cosine [i.e., cos(x)] estimating the value of "cos(x)" for a given argument, "x," value (in radians) Test your script [function) for arguments pi /6 and 3 pi /4 Your script should produce a Table of Results which illustrates the accuracy of the series approximation as the number of terms is increased.Explanation / Answer
% save as sqsum.m
x=input('enter the angle in radian');
sum=1;
m= 100;
for N=1:m
p=2*N;
v= 1;
for k=1:p
v=v*k;
end
sum=sum + (-1)^(N)* x^(p)/v;
end
fprintf('result = %12.7f ',sum)
>>sqsum
enter the angle in radian : pi
result = -1.0000000
>>sqsum
enter the angle in radian : 2*pi
result = 1.0000000
>>sqsum
enter the angle in radian : pi/2
result = 0.0000000
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.