Integration of a function with respect to a dummy variable

5 visualizaciones (últimos 30 días)
How to evaluate the integral ?
f(x) is integrated over a dummy variable z. Please note that x ((x(i) >= 0 or x(i) < 0)) is an array of n x 1 , and f(x) is a corresponding array of n x 1. I do not have the closed form expression for f(x), nor is curve fitting an option to approximate the data as an expression. How do I find corresponding vector A.
Kindly direct me to appropriate approach to solve this issue.

Respuesta aceptada

Nikhil Yewale
Nikhil Yewale el 6 de Mayo de 2020
Editada: Nikhil Yewale el 6 de Mayo de 2020
Hello
The issue is resolved by discussion with some friends
% say we are integrating a data resembling a parabola
x = -2:0.01:1;
y = x.^2;
% say you wanted to integrate from x = -2 to x = 0..
% (lower limit x = -2 is variable..may use a loop over x as per user's req.)
index = find(x == 0);
I = cumtrapz(x(1:index),y(1:index));
% any ' i'th ' element in 'I' denotes integration from x = -2 to x = x(i)
-I(end) % this should give integration of x.^2 from -2 to 0

Más respuestas (2)

Hiro Yoshino
Hiro Yoshino el 6 de Mayo de 2020
Why don't you think about using Symblic Math Toolbox?
You can manipulate your equation as you wish.
  1 comentario
Nikhil Yewale
Nikhil Yewale el 6 de Mayo de 2020
Hello Sir, Thanks for the prompt reply
Symbolic toolbox is useful, however I do not have an expression for the function. I just have set of two arrays,
say x = [-0.5 -0.2 -0.1 -0.05 0 0.1 0.3 0.7] and so on
and I have corresponding array , say f = [-0.9 -0.5 0.4 0.3 0 -0.3 -0.5 0.5]
Using these two arrays I wish to find the integral , where you can imagine lower limit being set to 0, and upper limit being varied with each element of x(i).
This is like cumulative integral with a minor detail that lower limit is always set to 0.

Iniciar sesión para comentar.


Hiro Yoshino
Hiro Yoshino el 6 de Mayo de 2020
f = [-0.9 -0.5 0.4 0.3 0 -0.3 -0.5 0.5]
let me assume z to be:
z = [0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0]
and
then
If you prefer continous manner, you should either approximate f as a function or interpolate the discrete numbers.
  1 comentario
Nikhil Yewale
Nikhil Yewale el 6 de Mayo de 2020
Thank you, Sir for your prompt reply,
I did get the idea that you were conveying from cumtrapz command and the issue is resolved.

Iniciar sesión para comentar.

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by