Borrar filtros
Borrar filtros

How do I integrate under a plot? (Non-functions)

30 visualizaciones (últimos 30 días)
Blair Hail-Brown
Blair Hail-Brown el 8 de Mzo. de 2022
Respondida: Nipun el 24 de En. de 2024
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 comentarios
Blair Hail-Brown
Blair Hail-Brown el 9 de Mzo. de 2022
This is one of the graphs I have plotted, with the values for Photon Flux being calculated through 2 separate equations (hence the 2 lines) using Lambda as an array. I would like to find the area under the graph to calculate the total value. Right now I am using trapz, but even when I change the index in the array for it to sample, it returns the same number consistently, whoch is several orders of magnitude smaller than it should be. Let me know if you want any code or anything else, as I said i realtly apppreciate the help
Torsten
Torsten el 9 de Mzo. de 2022
Editada: Torsten el 9 de Mzo. de 2022
The answer should be around 5e31*2000*1e-9 ~1e26

Iniciar sesión para comentar.

Respuestas (1)

Nipun
Nipun el 24 de En. de 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:
  1. 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
  2. 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

Categorías

Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by