XMIN must be a floating point scalar when xmin is from vpasolve

2 vues (au cours des 30 derniers jours)
Ying li
Ying li le 22 Mai 2019
Commenté : Ying li le 22 Mai 2019
I am trying to integrate the region between two surfaces. Their intersection can be solved numerically. Here is the code:
[solx,soly] = vpasolve([x.^2.*y.^2+x.^2+y.^2+2*x.*y-5 == 0, x.^2.*y+x+y==0],[x,y]) % find the left and right boundaries;
xmax=solx(3) % it turns out that the third entry is the right boundary I was looking for, which is 2.419...;
xmin=solx(4) % the four entry is the left boundary, which is -2.419...;
f = @(x,y) 5-x.^2-y.^2-x.*y-(x.^2.*y.^2+x.*y); % the function to be integrated;
ymax=@(x) (-2*x+sqrt(4*x.^2-4*(1+x.^2).*(x.^2-5)))./(2*(1+x.^2)); % upper boundary;
ymin=@(x) (-2*x-sqrt(4*x.^2-4*(1+x.^2).*(x.^2-5)))./(2*(1+x.^2)); % lower boundary;
I = integral2(f,xmin,xmax,ymin,ymax) % double integral;
This gives me the error message "XMIN must be a floating point scalar". I thought by indexing into solx, I already make xmax and xmin floating point scalars. In fact, in the 2nd and 3rd lines, the displays are
xmax =
xmin =
So why are they still not floating point scalars? And how to make them floating point scalars?
P.S. I tried to replace xmin by -2.42 and xmax by 2.42. It worked. I just want to understand why the above would not work.
Thank you!

Réponse acceptée

madhan ravi
madhan ravi le 22 Mai 2019
They are of symbolic type to convert them use double() :
xmax=double(solx(3));
xmin=double(solx(4));

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by