Error 'DOUBLE cannot convert the input expression into a double array'
Show older comments
I have symbolically integrated as following
function[flux]= superquad2(a1,a2,a3, epsilon1,epsilon2,epsilon3)
syms eta w
wmin=-pi/2;
wmax=pi/2;
etamin=-pi;
etamax=pi;
elp_x = a1.*abs(cos(eta)).^epsilon1.*abs(cos(w)).^epsilon1.*sign(cos(eta)).*sign(cos(w));
elp_y = a2.*abs(cos(eta)).^epsilon2.*abs(sin(w)).^epsilon2.*sign(cos(eta)).*sign(sin(w));
elp_z = a3.*abs(sin(eta)).^epsilon3.*sign(sin(eta));
ellipsoid=[elp_x,elp_y,elp_z];
ndseta=diff(ellipsoid,eta);
ndsw=diff(ellipsoid,w);
nds=cross(ndseta,ndsw);
F=[(a1.*abs(cos(eta)).*abs(cos(w))),(a2.*abs(cos(eta)).*abs(sin(w))),(a3.*abs(sin(eta)))];
F_par=subs(F,[(a1.*sign(cos(eta)).*abs(cos(eta)).*sign(cos(w)).*abs(cos(w))),(a2.*sign(cos(eta)).*abs(cos(eta)).*sign(sin(w)).*abs(sin(w))),(a3.*sign(sin(eta)).*abs(sin(eta)))],ellipsoid);
realdot=@(u,v)u*transpose(v);
fflux=realdot(F_par,nds);
fluxxx=symint2(fflux,w,wmin,wmax,eta,etamin,etamax);
fluxxxx=eval(fluxxx);
flux=double(fluxxxx);
end
To test the stability of the code, when I call this function with integer exponents it converges to a solution, but when I try with this
superquad2(25,25,25,.33,.66,.33)
the function returns the following error
Error using symengine
DOUBLE cannot convert the input expression into a double array.
Error in sym/double (line 643)
Xstr = mupadmex('symobj::double', S.s, 0);
Error in superquad2 (line 21)
flux=double(fluxxxx);
I could not understand it. I am starting to debug it but it doesn't help much.
Please help me to resolve the issue.
7 Comments
Adam
on 11 Jan 2019
What is symint2? And would you expect whatever it outputs, having gone through eval, which, frankly could produce anything, to be convertable to double?
Hirak
on 11 Jan 2019
Adam
on 11 Jan 2019
So why are you running the result through eval if it returns numerical results? I have no idea what eval does to numerical data as I never use it, but I don't see why it is used here.
Hirak
on 11 Jan 2019
Stephen23
on 11 Jan 2019
"It was used to evaluate the functional form obtained symbolically."
eval is not the right tool for that. It is not even listed as a symbolic toolbox function:
But that list does have a section entitled "Conversion Between Symbolic and Numeric", which includes double and vpa. Did you try either of the fucntions that are actually listed in the symbolic toolbox documenation?
Walter Roberson
on 11 Jan 2019
you should never eval something that is symbolic . The expression language used by the symbolic toolbox is not exactly the same as MATLAB .
Hirak
on 11 Jan 2019
Answers (2)
Walter Roberson
on 11 Jan 2019
1 vote
you should be using vpaintegral instead of int for that code.
double() of an int() forces int to try numeric integration, but with a different strategy than vpaintegral .
numeric integration through double() of int() or through vpaintegral() can fail such as if the function diverges or does not converge like int of sin to infinity . When you use double the only way to deal with that is try/catch. When you use vpaintegral it will reply back with aa vpaintegral when it is not able to calculate and you can look at the length of children() to determine whether you got back aa numeric result .
2 Comments
Hirak
on 11 Jan 2019
Walter Roberson
on 11 Jan 2019
vpaintegral is not a two dimensional .you need nested vpaintegral just like you use nested int()
5 Comments
Walter Roberson
on 14 Jan 2019
Look at the denominator of flux1 . It is 0 under several circumstances:
- eta = 0
- eta = pi/2
- eta = pi
- w = pi/2
- w = pi
- w = 3*pi/2
- w = 2*pi
You can show that the function crosses between -inf and +inf multiple times. These are unremovable singularities, and leave the integral undefined (because it becomes the sum of positive and negative infinities.)
Hirak
on 16 Jan 2019
Walter Roberson
on 16 Jan 2019
The denominator is 0 if:
- eta = -pi/2
- eta = 0
- eta = pi/2
- w = -pi
- w = -pi/2
- w = 0
- w = pi/2
- w = pi
So again you have unremovable singularities leading to sums of negative and positive infinities.
Hirak
on 16 Jan 2019
Walter Roberson
on 16 Jan 2019
You have a few choices:
- carefully control your integrations to not cross any of the singularities. As the singularties are not removable, then how close you get to the singularities will be important, as you will be adding and subtracting values approaching infinity.
- Check your equations again multiple times, paying particular attention to denominators and how they arise and why they can be zero. Perhaps you will find a reason why those situations do not really arise and can be avoided for your situation
- Check your equations again multiple times, paying particular attention to denominators and how they arise and why they can be zero. Perhaps you will find a reason why your situation is not solvable. For example, you have abs() and diff(abs) is not defined which tells you that your problem is not well posed.
- You could give up.
Categories
Find more on Conversion Between Symbolic and Numeric in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!