input N=1000000 function [N, C, pi_es] = co(N) C=0; Xcoord = rand(N,1); Ycoord =
ID: 3556140 • Letter: I
Question
input
N=1000000
function [N, C, pi_es] = co(N)
C=0;
Xcoord = rand(N,1);
Ycoord = rand(N,1);
for k=1:N;
x=Xcoord(k); y=Ycoord(k);
d=(x-0.5)^2 + (y-0.5)^2;
d=sqrt(d);
if (d<= 0.5);
C=C+1;
end
end
pi_es = 4*(C/N);
fprintf('co: N=%10d C=%10d pi_estimate=%7.4f ',N,C,pi_es);
end
RESULTS
co: N= 1000000 C= 785011 pi_estimate= 3.1400
ans =
1000000
Anyone know how i can fix this MATLAB script so i WONT print
ans =
1000000
when i run this program i only want to see the fprintf
co: N= 1000000 C= 785011 pi_estimate= 3.140
Explanation / Answer
N=1000000; % PUT SEMI COLON HERE.
function [N, C, pi_es] = co(N)
C=0;
Xcoord = rand(N,1);
Ycoord = rand(N,1);
for k=1:N;
x=Xcoord(k); y=Ycoord(k);
d=(x-0.5)^2 + (y-0.5)^2;
d=sqrt(d);
if (d<= 0.5);
C=C+1;
end
end
pi_es = 4*(C/N);
fprintf('co: N=%10d C=%10d pi_estimate=%7.4f ',N,C,pi_es);
end
co(N); % and call function like this with semi colon at end.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.