AboutGeorge Moustris Expertise I have extensive experience in MATLAB which is a CAD for engineers.I can answer many questions on the programming script as well as the use of many toolboxes Matlab uses.However DO NOT ask me about the underlying theory of your projects.I will only answer questions regarding the USE of Matlab.
Experience I have written many scripts in Matlab utilizing many toolboxes and libraries such as Fuzzy Logic toolbox,Neural Nets,Image processing,Wavelets,Signal processing etc.
Organizations Aristotle University of Thessaloniki
Expert: George Moustris Date: 9/21/2007 Subject: integrate tabulated XY data with Matlab
Question Dear allexperts,
I have a simple problem I need to resolve for research project I'm working on.
I have 1000 discrete values in Matlab already for r and
g(r) equally spaced. I need to calculate the integral between 0 and r of r^2 g(r) dr.
I already kown that Since I only have data points and not a function, I must use numerical intragration methods. for example Z = cumtrapz(X,Y). However I do not know yet how could I put inside the command cumtrapz r^2.
Thank you very much. Any help is much appreciated.
Javier
Answer Hello Javier,
you are correct about the cumtrapz function. What you need to do is to create another vector with the values of r^2g(r) and use this in the integration. This is how you can do it: suppose the values or r are in a vector called R (of course Matlab refers to it as a matrix of dimenions Nx1 or 1xN {column or row vector}). Let G be the vector for the g(r) values (accordingly its dimensions are Nx1 or 1xN). In order to create the data r^2g(r), you create another vector, call it F, and assign the values:
F=(R.*R).*G;
This will produce the vector F of length Nx1 (1xN) with the required values. You will then use this vector along with the vector R (the values of the integration variable "r") in the cumtrapz function.