I'm new to programming and have a problem with figuring this out:
clear all
close all
clc
x = [2 * rand(10)-1];
y = [2 * rand(10)-1];
p_i = sqrt(x.^2 + y.^2)
n = 0;
for k = 1:100
if p_i <= 1
n = n + 1
end
end
n
It gives me the answer n = 0. My intention is to make it count how many of the 100 times p_i is smaller than 1. I have two questions: How do I fix this problem? But more importantly how is MATLAB reading my code?
Aucun commentaire:
Enregistrer un commentaire