Integration of a function with respect to a dummy variable

조회 수: 7 (최근 30일)
Nikhil Yewale
Nikhil Yewale 2020년 5월 6일
편집: Nikhil Yewale 2020년 5월 6일
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.

채택된 답변

Nikhil Yewale
Nikhil Yewale 2020년 5월 6일
편집: Nikhil Yewale 2020년 5월 6일
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

추가 답변 (2개)

Hiro Yoshino
Hiro Yoshino 2020년 5월 6일
Why don't you think about using Symblic Math Toolbox?
You can manipulate your equation as you wish.
  댓글 수: 1
Nikhil Yewale
Nikhil Yewale 2020년 5월 6일
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.

댓글을 달려면 로그인하십시오.


Hiro Yoshino
Hiro Yoshino 2020년 5월 6일
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
Nikhil Yewale
Nikhil Yewale 2020년 5월 6일
Thank you, Sir for your prompt reply,
I did get the idea that you were conveying from cumtrapz command and the issue is resolved.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by