Numerical integration of tabulated data
3 次查看(过去 30 天)
显示 更早的评论
Hello,
I'm trying to follow the tutorial here so that I can generate a method of drawing a random number (between 0 and 1) to determine the scattering angle of a photon in a Monte Carlo simulation (of light propagating through water).
My phase function (beta tilde), scattering per Steradian vs. angle, is stored in a Matlab vector, betaFF. From the tutorial, a probability density function (PDF) is required to generate scattering angles from the random number (Tau)..." to determine the polar scattering angle, we draw a U[0,1] random number (Tau) and solve":
Furthermore: "In general (this equation) must be solved numerically because of the complicated shape of most phase functions, or when the phase function is defined by tabulated data at a finite number of scattering angles and is fit with a spline (or other) function to generate a continuous function of scattering angle."
A typical output, which is what I'm aiming to obtain, is shown at the bottom of that tutorial page:
I can fit the tabulated betaFF values using Matlab's "fit" function and 'linearinterp', as described in the tutorial (tabulated data at a finite number of scattering angles...is fit with a spline (or other) function):
func = fit(psi,betaFF,'linearinterp');
where psi is a vector containing angles from 0 to 180 degrees.
From there, I get pretty lost. I don't know how I'm supposed to use this linear fit (func) to numerically evaluate the equation above. Is it possible to create a function in Matlab containing both "func" and the sin(psi) term and integrate that? Any pointers would be very welcome.
0 个评论
回答(1 个)
Steven Lord
2017-9-7
Since you've fitted a function you can use the integrate function on the func object. If you wanted to numerically integrate a vector or matrix of data, use trapz or cumtrapz as shown in this example.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interpolation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!