Numerical approximation of the area under curve

Click For Summary

Discussion Overview

The discussion revolves around the numerical approximation of the area under a curve using MATLAB, specifically in the context of gamma ray spectroscopy. Participants are exploring how to integrate a specific photo peak area that is not aligned with the x-axis, and they are sharing their experiences and challenges with MATLAB coding.

Discussion Character

  • Exploratory
  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant expresses confusion about how to integrate the area under a photo peak that is off the x-axis using MATLAB.
  • Another participant suggests that the green area in the graph appears to be a rectangle, proposing that its area could be computed and subtracted from the total integral to isolate the desired area.
  • Some participants indicate uncertainty about how to compute the area of a rectangle in MATLAB, with one participant mentioning they have been learning MATLAB through tutorials.
  • A participant identifies a potential issue in their code related to a misspelled function name, which may have affected their calculations.

Areas of Agreement / Disagreement

There is no consensus on the best approach to isolate the area of interest, as participants are exploring different methods and expressing varying levels of familiarity with MATLAB.

Contextual Notes

Participants have not fully resolved the mathematical steps required to integrate the specific area under the curve, and there are dependencies on their understanding of MATLAB functions and coding practices.

Taylor_1989
Messages
400
Reaction score
14
I am very new too Matlab and how it all works but I am having trouble understanding at what axis the numerical integration is occurring from on the graph that I plotted.

So I am currently doing an experiment in gamma ray spectroscopy and due to issue with the software we found it hard to integrate under a specific photo peak so it was suggest to use Matlab to integrate under the area, but the photo peak is off the x-axis so which I have highlighted in my picture below.

c60_unattenuated area 1.png

But my issue is I don't know how to integrate that specific area in Matlab, so what I have done so far is cherry pick the data and fit a Gaussian to it which produced the given function and graph.

Firstly here is my data set I picked for the curve
1117.4 7
1120.4 9
1123.4 7
1126.4 13
1129.4 6
1132.4 14
1135.4 15
1138.4 11
1141.4 20
1144.4 16
1147.5 16
1150.5 18
1153.5 33
1156.5 20
1159.5 19
1162.5 24
1165.5 35
1168.5 35
1171.5 43
1174.5 42
1177.5 40
1180.5 38
1183.5 38
1186.5 37
1189.5 34
1192.5 39
1195.5 34
1198.5 25
1201.6 23
1204.6 23
1207.6 19
1210.6 19
1213.6 13
1216.6 10
1219.6 16
1222.6 10
1225.6 6
1228.6 2
1231.6 11
1234.6 11
1237.6 5
1240.6 7

Next here is my code to plot the data

Code:
dataset = xlsread('Lab 3 Results 11.10.18 (1).xlsx','Sheet3','C390:D431');
x=dataset(:,1);
%y=dataset(:,2);
%plot(x,y,'-')
a1=37.43 ;
b1=1178  ;
c1=39.28  ;
d1=0
y=a1*exp(-((x-b1)/c1).^2)-d1;
%int1=trapz(x,y)
%int2=trapz(y)
plot(x,y)
%xlabel('Energy : KeV', 'FontSize', 15)
%ylabel('Number Of Interactions','FontSize', 15)

Ignore comment out parts I am currently experimenting

this produced the following graph

c60_unattenuated area 2.png
c60_unattenuated area 2.png


so now this is the part hat get confusing for me I need to calculate the area in the red but when i used the trapz(x,y) I think it is finding the area of both red and green, my only option at the moment I think is to shift the graph down so it aligns with the x=0 axis and it should integrate just the red area is this correct?
 

Attachments

  • c60_unattenuated area 1.png
    c60_unattenuated area 1.png
    9.6 KB · Views: 929
  • c60_unattenuated area 2.png
    c60_unattenuated area 2.png
    4 KB · Views: 858
Physics news on Phys.org
The green part looks to be a rectangle, it should be straightforward to compute its area and subtract that from the integral.
 
Orodruin said:
The green part looks to be a rectangle, it should be straightforward to compute its area and subtract that from the integral.

The issue is I don't know how to do that in matlab, I am not sure where to start
 
Taylor_1989 said:
The issue is I don't know how to do that in matlab, I am not sure where to start
You don't know how to compute the area of a rectangle in Matlab?
 
Orodruin said:
You don't know how to compute the area of a rectangle in Matlab?
yes, iv done by hand easy, but i literally have been using youtube as tutorials, and have only been doing MATLAB for a week, so at the moment I am learning as I go. I did have ago at creating a function of a rectangle but it would not complie, I see if I can find the code
 
Ah i think I found my issue in my code, I misspelt the function name.
 

Similar threads

Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 6 ·
Replies
6
Views
6K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
2
Views
952
  • · Replies 2 ·
Replies
2
Views
3K