I need to understand how I can translate these few lines of MATLAB code. I don't understand how to create a vector n1
of n
elements and how to fill it using the same formula as in MATLAB.
Here's the MATLAB code:
nc = 200; ncmax = 600; dx = 0.15e-04;
r = (dx/2):dx:dx*(ncmax+3);
n1(1:nc) =(1 ./ (s.*sqrt(2*pi).*r(1:nc))).*exp(-((log(r(1:nc)) - med).^2)./(2*s^2));
I have the following in Python, but n1
is always an empty array of nc
elements:
import numpy as np
r =np.arange((dx/2),(dx*(ncmax+3)),dx)
count=1
n1=np.empty(nc)
while (count<nc)
n1[count]=(1/(s*np.sqrt(2*pi)*r[count]))*np.exp(-((np.log(r[count]))-med)**2)/(2*s**2)
count=count+1