n = input('Podaj n = ') % prosi o podanie liczby losowanych punktów
for k = 1: n
x = rand;
y = rand;
r = sqrt(x^2 + y^2);
if (r <= 1) % jeżeli wylosowany punkt jest w kole o promieniu r =1
nkolo = nkolo + 1;
end
end
p = 4*nkolo/n;
d = abs(pi - p); % błąd bezwzględny
dw = 100*d/pi; % błąd względny podany w procentach
disp(['Pi = ' num2str(p)])
disp(['delta = ' num2str(d)])
disp(['delta % = ' num2str(dw)])
end
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team