How do I integrate under a plot? (Non-functions)
이전 댓글 표시
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
Benjamin Thompson
2022년 3월 8일
I use cumsum for numerical integration, and multiply the result by the sampling interval or step size. If the step size is variable then use the element multiply operator .*
For a better answer we may need to see some sample data.
Blair Hail-Brown
2022년 3월 9일
답변 (1개)
Nipun
2024년 1월 24일
0 개 추천
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)

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

area_under_curve = 2.0000
Hope this helps.
Regards,
Nipun
카테고리
도움말 센터 및 File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
