Error 'DOUBLE cannot convert the input expression into a double array'
이전 댓글 표시
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
Adam
2019년 1월 11일
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
2019년 1월 11일
Adam
2019년 1월 11일
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
2019년 1월 11일
Stephen23
2019년 1월 11일
"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
2019년 1월 11일
you should never eval something that is symbolic . The expression language used by the symbolic toolbox is not exactly the same as MATLAB .
Hirak
2019년 1월 11일
답변 (2개)
Walter Roberson
2019년 1월 11일
1 개 추천
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
Hirak
2019년 1월 11일
Walter Roberson
2019년 1월 11일
vpaintegral is not a two dimensional .you need nested vpaintegral just like you use nested int()
댓글 수: 5
Walter Roberson
2019년 1월 14일
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
2019년 1월 16일
Walter Roberson
2019년 1월 16일
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
2019년 1월 16일
Walter Roberson
2019년 1월 16일
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.
카테고리
도움말 센터 및 File Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!