Numerical integration of tabulated data
11 views (last 30 days)
Show older comments
Jonathan on 7 Sep 2017
Commented: Jonathan on 8 Sep 2017
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.
Steven Lord on 7 Sep 2017
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.
Find more on Smoothing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!