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 Kommentare

VBBV
VBBV am 10 Okt. 2020
Bearbeitet: Walter Roberson am 10 Okt. 2020
Use syms to define it as symbolic variable
syms c
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)
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 10 Okt. 2020

0 Stimmen

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 Kommentare

Tron
Tron am 10 Okt. 2020
Thanks Walter, I will do my Matlab dance and hope for the best.
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 ?
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))

Melden Sie sich an, um zu kommentieren.

Produkte

Version

R2020b

Gefragt:

am 9 Okt. 2020

Kommentiert:

am 10 Okt. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by