필터 지우기
필터 지우기

How to apply integral on a vector?

조회 수: 68 (최근 30일)
Nour EL SABBAGH
Nour EL SABBAGH 2020년 5월 8일
댓글: Nour EL SABBAGH 2020년 5월 13일
Hello,
I have a problem that I can't find the right answer to.
I have these equations:
y = x ^ 2 ;
z = y dx = x^2 dx = 1/3 * x^3;
In Matlab code, let's consider two vectors:
x = -20 : 1 : 20 ;
y = x . * x ;
z = y dx ; which we already know the answer to, that is: z = x . * x . * x * 1/3;
I would like to calculate the vector z with some command without the need to create a function, as I do not own Symbolic Math Toolbox, or any other Toolbox needed.
Can someone help me with this? Maybe write the corresponding code that goes with it?
Thank You in advance.

답변 (1개)

Nikhil Yewale
Nikhil Yewale 2020년 5월 8일
1) Using function handle without specifying explicity whole array
a = -20; b = 20; % lower limit a, upper limit b
y = @(x) x.^2; % create fuction handle of x , followed by function definition
I = integral(y,a,b); % required answer
2) With whole array x.. You may check that required integral is same by both methods
dx = 0.01; % increment in x array
X = a:dx:b; %array X
cumulative_I = dx*cumtrapz(X.^2); % evaluates cumulative integral using traezoidal method
II = cumulative_I(end); % required answer
  댓글 수: 2
Nour EL SABBAGH
Nour EL SABBAGH 2020년 5월 8일
Thank You very much for your explicit answer, this is what I was looking for !!
Thank you, saved my day !
Nour EL SABBAGH
Nour EL SABBAGH 2020년 5월 13일
hello again,
Following my question here, I am looking to find again the value of y'=y, by derivation of z:
y = x^2 ;ss
z = y dx ;
y' = dz/dx = d(1/3*x^3)/dx = x^2 = y ;
With the integration using your second method, I find z correctly.
To find y'=diff(z), diff gives me a vector of one fewer element, which is logical.
But I do need to find the exact vector y=y'. Does anyone know an alternative function to diff(z) that does not need any function creation? Maybe write me the corresponding code that goes with it if it is complicated?
Thank You in advance.

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by