|
Hi, I have been trying for a while and with no success to solve the following simple problem without using "for" loops.
I have a predefined equally-spaced 1D grid of values , say
a=linspace(a_min,a_max,n);
I also have a vector of values s of the same size n with
max(s)<a_max and min(s)>a_min;
What I want to obtain is a probability mass function f(a) such that density associated to each s(i) is distributed to the grid values of a bracketing s(i) according to the relative distance of s(i) from such values.
In other words, suppose s(i) is bracketed by a(j) and a(j+1), then
f(a(j+1))=(s(i)-a(j))/(a(j+1)-a(j))
f(a(j))=1-f(a(j+1)).
I clearly was able to compute f(a) using for loops, but since both na and ns are pretty large (between 5000 and 10000) and since this computation is inside an fsolve I am looking for a smart way to vectorize it.
Thank you,
Massimo
|