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

2 ビュー (過去 30 日間)
Daniel Caliari
Daniel Caliari 2017 年 2 月 5 日
コメント済み: Walter Roberson 2017 年 2 月 6 日
Hi! How could I writte a code to integrate the expression in relation to x(1) only?
a = @(x)x(1) + x(2)^2;

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 2 月 5 日
You would have to use the symbolic toolbox
syms x1 x2
int(a([x1,x2]), x1, LowerBound, UpperBound)
  2 件のコメント
Daniel Caliari
Daniel Caliari 2017 年 2 月 5 日
Can't I use function handle?
Walter Roberson
Walter Roberson 2017 年 2 月 6 日
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)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by