Evaluating double integral with unknown variable in

Hi,
I am trying to evaluate a double integral of x,y with an unkown constant c. The result for c should resemble a binomial distribution. I am trying to solve this using integral2 as follows:
fun = @(x,y)(((c-y+x)^50)*((1-c+y-x)^3280)*(y^50)*((1-y)^130)*((x^16)*((1-x)^3308)))
xmax = @(y)(1-c+y)
xmin = @(y)(y-c)
q = integral2(fun,0,1,xmin,xmax)
But I get a list of errors:
Unrecognized function or variable 'c'.
Error in stupidstupid>@(y)(y-c) (line 3)
xmin = @(y)(y-c)
Error in integral2Calc>integral2t/tensor (line 189)
bottom = YMIN(x);
Error in integral2Calc>integral2t (line 55)
[Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);
Error in integral2Calc (line 9)
[q,errbnd] = integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);
Error in integral2 (line 106)
Q = integral2Calc(fun,xmin,xmax,yminfun,ymaxfun,opstruct);
Error in stupidstupid (line 4)
q = integral2(fun,0,1,xmin,xmax)
I think this has to do with the fact that I have not define the variable c, but I do now know how to define it. Any help would be greatly appreciated. Thanks in Advance!

3 件のコメント

VBBV
VBBV 2020 年 10 月 10 日
編集済み: Walter Roberson 2020 年 10 月 10 日
Use syms to define it as symbolic variable
syms c
Tron
Tron 2020 年 10 月 10 日
Thanks Vasishta,
That got me somewhere, but it seems like it does not want to return an expression in terms of c:
Error using integral2Calc>integral2t/tensor (line 194)
Input function must return 'double' or 'single' values. Found 'sym'.
Error in integral2Calc>integral2t (line 55)
[Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);
Error in integral2Calc (line 9)
[q,errbnd] = integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);
Error in integral2 (line 106)
Q = integral2Calc(fun,xmin,xmax,yminfun,ymaxfun,opstruct);
Error in stupidstupid (line 5)
q = integral2(fun,0,1,xmin,xmax)
Walter Roberson
Walter Roberson 2020 年 10 月 10 日
integral() and integral2() require that the function returns a numeric value. They are adaptive numeric integrations and need the numeric values to figure out whether they need to refine further.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 10 月 10 日

0 投票

you can never use integral() or intrgral2() when you have undefined variables. You have to use symbolic integration and hope that matlab can solve it.

3 件のコメント

Tron
Tron 2020 年 10 月 10 日
Thanks Walter, I will do my Matlab dance and hope for the best.
Walter Roberson
Walter Roberson 2020 年 10 月 10 日
It is not necessarily impossible to integrate symbolically, but symbolic integration will probably require expanding out the (1-x)^3308 and (1-c+y-x)^3280 and so on, and doing all of the polynomial multiplications, and finally doing the integration.
Those are really large powers... how did they originate ?
Walter Roberson
Walter Roberson 2020 年 10 月 10 日
My tests suggest that the final result would be a polynomial of degree 16+3308 = 3324. where those numbers come from ((x^16)*((1-x)^3308))

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

カテゴリ

製品

リリース

R2020b

質問済み:

2020 年 10 月 9 日

コメント済み:

2020 年 10 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by