Warning: Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your function to return an output with the same size and shape as the input arguments.

3 visualizaciones (últimos 30 días)
Hello,
I want to visualize a cost function of a localization problem. However if i use fimplicit3 the following warning appears: "Warning: Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your function to return an output with the same size and shape as the input arguments" and the plot is empty. Here is my code:
syms x y z
Jd=(-(((x - 10)^2 + (y - 8)^2 + (z - 1/10)^2)^(1/2)/343 - ((x - 9)^2 + (z - 1/10)^2 + y^2)^(1/2)/343 + 166153461756515/288230376151711744)*((1227133513142857*((y - 3)^2 + (z - 1)^2 + x^2)^(1/2))/841813590016 + (8589934592000001*((x - 9)^2 + (z - 1/10)^2 + y^2)^(1/2))/5892695130112 + (500000*((x - 5)^2 + (y - 10)^2 + (z - 3/2)^2)^(1/2))/343 - (1500000*((x - 10)^2 + (y - 8)^2 + (z - 1/10)^2)^(1/2))/343 + 47361719490181303919776257030055/4951760157141521099596496896) - (((y - 3)^2 + (z - 1)^2 + x^2)^(1/2)/343 - ((x - 9)^2 + (z - 1/10)^2 + y^2)^(1/2)/343 + 3755404798969945/288230376151711744)*((500000*((x - 9)^2 + (z - 1/10)^2 + y^2)^(1/2))/343 - (1500000*((y - 3)^2 + (z - 1)^2 + x^2)^(1/2))/343 + (8589934592000001*((x - 5)^2 + (y - 10)^2 + (z - 3/2)^2)^(1/2))/5892695130112 + (1227133513142857*((x - 10)^2 + (y - 8)^2 + (z - 1/10)^2)^(1/2))/841813590016 - 75964017393466287210169242730447/4951760157141521099596496896) - (((x - 5)^2 + (y - 10)^2 + (z - 3/2)^2)^(1/2)/343 - ((x - 9)^2 + (z - 1/10)^2 + y^2)^(1/2)/343 + 564171350756517/72057594037927936)*((8589934592000001*((y - 3)^2 + (z - 1)^2 + x^2)^(1/2))/5892695130112 + (1227133513142857*((x - 9)^2 + (z - 1/10)^2 + y^2)^(1/2))/841813590016 - (1500000*((x - 5)^2 + (y - 10)^2 + (z - 3/2)^2)^(1/2))/343 + (500000*((x - 10)^2 + (y - 8)^2 + (z - 1/10)^2)^(1/2))/343 - 4.9414e+03));
fs=@(x,y,z)double(Jd);
fimplicit3(fs,[-30 30 -30 30 -30 30]);
Due to the fact that the cost function is calculated out of a localization problem it's so huge.

Respuesta aceptada

Walter Roberson
Walter Roberson el 13 de Jul. de 2020
syms x y z
Jd = (-(((x - 10)^2 + (y - 8)^2 + (z - 1/10)^2)^(1/2)/343 - ((x - 9)^2 + (z - 1/10)^2 + y^2)^(1/2)/343 + 166153461756515/288230376151711744)*((1227133513142857*((y - 3)^2 + (z - 1)^2 + x^2)^(1/2))/841813590016 + (8589934592000001*((x - 9)^2 + (z - 1/10)^2 + y^2)^(1/2))/5892695130112 + (500000*((x - 5)^2 + (y - 10)^2 + (z - 3/2)^2)^(1/2))/343 - (1500000*((x - 10)^2 + (y - 8)^2 + (z - 1/10)^2)^(1/2))/343 + 47361719490181303919776257030055/4951760157141521099596496896) - (((y - 3)^2 + (z - 1)^2 + x^2)^(1/2)/343 - ((x - 9)^2 + (z - 1/10)^2 + y^2)^(1/2)/343 + 3755404798969945/288230376151711744)*((500000*((x - 9)^2 + (z - 1/10)^2 + y^2)^(1/2))/343 - (1500000*((y - 3)^2 + (z - 1)^2 + x^2)^(1/2))/343 + (8589934592000001*((x - 5)^2 + (y - 10)^2 + (z - 3/2)^2)^(1/2))/5892695130112 + (1227133513142857*((x - 10)^2 + (y - 8)^2 + (z - 1/10)^2)^(1/2))/841813590016 - 75964017393466287210169242730447/4951760157141521099596496896) - (((x - 5)^2 + (y - 10)^2 + (z - 3/2)^2)^(1/2)/343 - ((x - 9)^2 + (z - 1/10)^2 + y^2)^(1/2)/343 + 564171350756517/72057594037927936)*((8589934592000001*((y - 3)^2 + (z - 1)^2 + x^2)^(1/2))/5892695130112 + (1227133513142857*((x - 9)^2 + (z - 1/10)^2 + y^2)^(1/2))/841813590016 - (1500000*((x - 5)^2 + (y - 10)^2 + (z - 3/2)^2)^(1/2))/343 + (500000*((x - 10)^2 + (y - 8)^2 + (z - 1/10)^2)^(1/2))/343 - 4.9414e+03));
N = 20;
[X, Y, Z] = ndgrid(linspace(-30, 30, N));
result = double(subs(Jd, {x, y, z}, {X, Y, Z}));
isosurface(X, Y, Z, result, 0)
xlabel('x'); ylabel('y'); zlabel('z');
Unfortunately at the moment, my system is busy so I cannot tell how well the graphic worked. I suspect you will need to increase N to get better resolution.
  5 comentarios
Walter Roberson
Walter Roberson el 13 de Jul. de 2020
When you apply fminsearch to the square of the cost function, then provided the cost function values cannot be imaginary, what you are searching for is zeros of the cost function. This fminsearch is relatively fast, and gives you a point on (near) the surface.
A big problem with the fimplicit3 and the ndgrid approaches is that they depend upon finding very close starting points, since the formula is too complex for areas outside to be of much use in finding the surface.
Once you know a point on (near) the surface, and knowing that you are dealing with an ellipsoid, you should be able to probe around to find the extent of the ellispsoid, such as
temp = 10.^(-10:0);
delta = [-fliplr(temp), 0, temp];
now use delta as offsets to each coordinate in turn, and look for positive (outside), negative(inside), positive (outside) pattern in each dimension. Then pick a grid from that, ndgrid, evaluate, isosurface on value 0

Iniciar sesión para comentar.

Más respuestas (1)

madhan ravi
madhan ravi el 13 de Jul. de 2020
fs = matlabFunction(Jd)
  4 comentarios
Max Lacher
Max Lacher el 13 de Jul. de 2020
I have already waited for a long time and I don't think that the computer is still calculating.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by