%%Matlab code for Monte Carlo simulation for finding area of
circle
clear all
close all
%Radius of the circle
r=1;
% number of points generated
N = 10;
a = -r;
b = r;
x = a + (b-a).*rand(N,1);
y = a + (b-a).*rand(N,1);
radii = sqrt(x.^2+y.^2);
hits = sum(radii<=1);
th=linspace(0,2*pi);
x_r=cos(th);
y_r=sin(th);
figure(1)
plot(x_r,y_r,'Linewidth',2)
%Plotting data
k=0;
hold on
for i=1:N
radd=sqrt((x(i)).^2+(y(i)).^2);
if radd<=1
k=k+1;
xx(k)=x(i);
yy(k)=y(i);
plot(x(i),y(i),'r*')
else
plot(x(i),y(i),'b*')
end
end
xlim([-1 1])
ylim([-1 1])
title(sprintf('Monte Carlo plot for N=%d',N))
xlabel('x')
ylabel('y')
ar=4*hits/N;
fprintf('\n\tFor N=%d area of Circle using Monte Carlo method is
%f.\n',N,ar)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
%Radius of the circle
r=1;
% number of points generated
N = 100;
a = -r;
b = r;
x = a + (b-a).*rand(N,1);
y = a + (b-a).*rand(N,1);
radii = sqrt(x.^2+y.^2);
hits = sum(radii<=1);
th=linspace(0,2*pi);
x_r=cos(th);
y_r=sin(th);
figure(2)
plot(x_r,y_r,'Linewidth',2)
%Plotting data
k=0;
hold on
for i=1:N
radd=sqrt((x(i)).^2+(y(i)).^2);
if radd<=1
k=k+1;
xx(k)=x(i);
yy(k)=y(i);
plot(x(i),y(i),'r*')
else
plot(x(i),y(i),'b*')
end
end
xlim([-1 1])
ylim([-1 1])
title(sprintf('Monte Carlo plot for N=%d',N))
xlabel('x')
ylabel('y')
ar=4*hits/N;
fprintf('\n\tFor N=%d area of Circle using Monte Carlo method is
%f.\n',N,ar)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
%Radius of the circle
r=1;
% number of points generated
N = 1000;
a = -r;
b = r;
x = a + (b-a).*rand(N,1);
y = a + (b-a).*rand(N,1);
radii = sqrt(x.^2+y.^2);
hits = sum(radii<=1);
th=linspace(0,2*pi);
x_r=cos(th);
y_r=sin(th);
figure(3)
plot(x_r,y_r,'Linewidth',2)
%Plotting data
k=0;
hold on
for i=1:N
radd=sqrt((x(i)).^2+(y(i)).^2);
if radd<=1
k=k+1;
xx(k)=x(i);
yy(k)=y(i);
plot(x(i),y(i),'r*')
else
plot(x(i),y(i),'b*')
end
end
xlim([-1 1])
ylim([-1 1])
title(sprintf('Monte Carlo plot for N=%d',N))
xlabel('x')
ylabel('y')
ar=4*hits/N;
fprintf('\n\tFor N=%d area of Circle using Monte Carlo method is
%f.\n',N,ar)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
in Matlab, Use the Monte Carlo analysis to compute the area of a circle with radius 1. print out your code, at least one figure on which the circle and ‘dart hits’ are shown, and numerical results fo...
Part 1: Use principles of inheritance to write code calculating the area, surface area, and volume of rectangular objects. First, write an abstract super class RectangularShape, then write a subclass Rectangle that inherits from the super class to compute areas of rectangles, including squares if there is only one data. Finally, write another subclass Cuboid that inherits from its super class Rectangle above to compute surface areas and volumes of cuboids, including 3 equal sided cube. Must apply code-reusability in...
Assignment Specifications We are going to use the Monte Carlo Method to determine the probability of scoring outcomes of a single turn in a game called Pig. Your Task For this assignment you will simulate a given number of hold?at?N turns of a game called Pig, and report the estimated probabilities of the possible scoring outcomes. You are NOT implementing the game of Pig, only a single turn of this game. The value of N will be acquired via user...
I wrote a program which computes the area and perimeter of a square, circle, or rectangle. As you will see in my main function, there is a for loop in which the user is supposed to be able repeat the program until they enter "q" to quit. However, my program runs through one time, the prompt appears again, but then it terminates before the user is allowed to respond to the prompt again. I'm not able to debug why this...
This is a matlab HW that I need the code for, if someone could help me figure this out it would be appreciated. The value of t can be estimated from the following equation: in your script file, estimate the value of π for any number of terms. You must ask the user for the desired number of terms and calculate the absolute error/difference between your calculation and the built-in MATLAB value ofpi. Display your results with the following message...
In C++ Do not use a compiler like CodeBlocks or online. Trace the code by hand. Do not write "#include" and do not write whole "main()" function. Write only the minimal necessary code to accomplish the required task. Save your answer file with the name: "FinalA.txt" 1) (2 pts) Given this loop int cnt = 1; do { cnt += 3; } while (cnt < 25); cout << cnt; It runs ________ times ...
A. Introduction and Objective Every test has at least two sources of variation that affect the results of the test. The first source of variation is due to the experimental procedure, such as using two different testing machines that have different calibrations, or different observers reading the same equipment differently. This type of variation is often called the experimental error The second source of variation is inherent in the specimens (or sample population) themselves. In other words, no two specimens...
Consider a cylindrical capacitor like that shown in Fig. 24.6. Let d = rb − ra be the spacing between the inner and outer conductors. (a) Let the radii of the two conductors be only slightly different, so that d << ra. Show that the result derived in Example 24.4 (Section 24.1) for the capacitance of a cylindrical capacitor then reduces to Eq. (24.2), the equation for the capacitance of a parallel-plate capacitor, with A being the surface area of...
please use python and provide run result, thank you! click on pic to make it bigger For this assignment you will have to investigate the use of the Python random library's random generator function, random.randrange(stop), randrange produces a random integer in the range of 0 to stop-1. You will need to import random at the top of your program. You can find this in the text or using the online resources given in the lectures A Slot Machine Simulation Understand...