How do I integrate under a plot? (Non-functions)
29 views (last 30 days)
Show older comments
I have been modelling Black-Body Radiation for different temperature bodies, and have converted this into Photon Flux. I now would like to know the total amount of Photonsbeing emitted from the body. I want to integrate under the curve I have plotted against wavelength, hwoever the integral function seems to only apply to functions. I used trapz, but my final answeer was to the order of 10^25, and the max values of the plot are 10^31. Any help would be massively appreciated
3 Comments
Answers (1)
Nipun
on 24 Jan 2024
Hi Blair,
I understand that you are trying to find the area under the curve for the given plot without using symbolic math for MATLAB. I assume that the plot is computed using discrete values: discerete values of wavelength and corresponding values of photon flux.
Since the data is discrete, there are two ways to compute the area under the curve:
- Fit the data using a data fitting funtion to retrieve the plot equation. This equation (or symbolic function) can be then utilized to compute the area under the curve by integration. More information on fitting data in MATLAB can be found here: https://in.mathworks.com/help/curvefit/fit.html
- Utilize approximation methods to approximate area under the curve. The accuracy of the output depends on the step size (difference between consecutive "x" axis values) and how fast the "y" axis changes with change in "x". More information on approximating area under curve can be found here: https://courses.lumenlearning.com/calculus1/chapter/approximating-area/#:~:text=With%20a%20left%2Dendpoint%20approximation,the%20areas%20of%20the%20rectangles.&text=Figure%209.,for%20a%20left%2Dendpoint%20approximation.
Since the plot does not seem to change dramatically with change in "x" and both of the listed approaches result in an approximation, I recommend the second approach to get an area estimate.
As there is no sample data provided, please modify the following example where I plot the "sine" function in range [0, pi/2] and calculate the area under the curve. Notice decreasing the step-size increases the accuracy of the estimate.
% declaring a step size (difference between two adjacent x-axis values)
step_size = 0.5;
% declare x,y variables where y = sin(x)
x = 0 : step_size : pi; % range from 0 to pi with step size of 0.1
y = sin(x);
% plotting
plot(x,y);
% calculate the area under curve
% Note that the actual value of integrating sin(x) in [0, pi/2] is "2"
area_under_curve = sum(step_size.*y)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1598546/image.png)
area_under_curve = 1.9836
% gives area under curve of 1.9836
% declaring a step size (difference between two adjacent x-axis values)
step_size = 0.01;
% declare x,y variables where y = sin(x)
x = 0 : step_size : pi; % range from 0 to pi with step size of 0.1
y = sin(x);
% plotting
plot(x,y);
% calculate the area under curve
% Note that the actual value of integrating sin(x) in [0, pi/2] is "2"
area_under_curve = sum(step_size.*y)
% gives area under curve of 2.000
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1598551/image.png)
area_under_curve = 2.0000
Hope this helps.
Regards,
Nipun
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!