How to use integral() in a multi variable expression?

2 Ansichten (letzte 30 Tage)
Daniel Caliari
Daniel Caliari am 5 Feb. 2017
Kommentiert: Walter Roberson am 6 Feb. 2017
Hi! How could I writte a code to integrate the expression in relation to x(1) only?
a = @(x)x(1) + x(2)^2;

Antworten (1)

Walter Roberson
Walter Roberson am 5 Feb. 2017
You would have to use the symbolic toolbox
syms x1 x2
int(a([x1,x2]), x1, LowerBound, UpperBound)
  2 Kommentare
Daniel Caliari
Daniel Caliari am 5 Feb. 2017
Can't I use function handle?
Walter Roberson
Walter Roberson am 6 Feb. 2017
That does use a function handle. It invokes the function handle a on the input [x1, x2], returning the symbolic expression x1 + x2^2 which is then integrated. If you need to turn the symbolic result back into a function handle then you can use matlabFunction .
If your question is whether you can use integral() to do an integral over one of the variables leaving the other undefined, then the answer is NO.
It is possible to do a 2D numeric integral using integral2(), such as
a = @(x)x(1) + x(2).^2; %vectorize it!
fa = @(x,y) a([x,y])
integral2(fa, xlow, xhigh, ylow, yhigh)

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by