So i have this code writen in python. I'm not going to explain it as it is a simple syntax fix that i can't seem to see so it is useless to explain what's for.
The problem that i have is that for a given d, for example 15 i get the value of "cuentas" right and "e" correct.
What i want to do is to iterate through a set of d's and get the value of each cuentas, and each e in order to plot d vs e.
My problem is that i dont seem to get how to create a matrix in python.
In matlab i used to write two different loops like theese:
for i=1:1:N
for j=1:9
a[i,j]= and so on
a[i,j] would be a matrix with N rows and 9 columns that i could access and manipulate.
In my code below i will intentionaly put # comments where i want to iterate through the distances
import numpy as np
import matplotlib.pyplot as plt
N=100000
cos=np.zeros(N)
phi=np.zeros(N)
teta=np.zeros(N)
a=np.zeros(N)
xrn=np.zeros(N)
yrn=np.zeros(N)
zrn=np.zeros(N)
x=np.zeros(N)
y=np.zeros(N)
z=np.zeros(N)
lim1=14.7
lim2=3.35
lim3=-lim1
lim4=-lim2
#d=np.array([15,20,25,30,35,40,45,50,55])
d=15
#for j in range(9):
for i in range(N):
cos[i]=np.random.uniform(-1,1)
teta[i]=np.random.uniform(-np.pi,np.pi)
phi[i]=np.random.uniform(0,2*np.pi)
# a[i]=d[j]/cos[i]*np.cos(phi[i])
a[i]=d/cos[i]*np.cos(phi[i])
xrn[i]=np.random.uniform(-1,1)*lim1
yrn[i]=np.random.uniform(-1,1)*lim2
x[i]=a[i]*np.sin(teta[i])*np.cos(phi[i])+xrn[i]
y[i]=a[i]*np.sin(teta[i])*np.sin(phi[i])+yrn[i]
#cuentas[j]=0
cuentas=0
#for j in range(9):
for i in range(N):
if a[i]>0 and x[i] < lim1 and x[i]>lim3 and y[i] < lim2 and y[i]>lim4:
cuentas=cuentas+1
#e[j]=cuenta[j]/N
e=cuentas/N
Thanks so much to those even reading!!