Pregunta

I am trying to solve four algebraic equations in a for loop. It is giving a warning 'Possibly spurious solutions'. Could you please help me to figure out how to remove it. Code is attached herewith.

a=[1.78E-05 3.39E-04    0.0104  -0.05791    -16.36];

for i=1:R/l0
    syms x y l r
    [sol_l,sol_r,sol_x,sol_y] = solve(l == (sqrt((x-x0)^2+(y-y0)^2)), r == abs((x+x0)/2),...
    poly2sym(a) == y, l*r*t == l0*r0*t0,x,y,l,r, 'Real', true);
    for j=1:length(sol_x)
        if (sol_x(j)<0)&&(sol_x(j)>x0)
            if (sol_y(j)<0)&&(sol_y(j)<y0)
                x_req(1,i) = sol_x(j);
                y_req(1,i) = sol_y(j);
            end
        end
    end
    x0 = x_req(1,i);
    y0 = y_req(1,i);
    r0 = R-l0*(2*i-1)/2;    
   end
¿Fue útil?

Solución

If you change your first equation to this, the warning no longer crops up:

l^2 == (x-x0)^2+(y-y0)^2

I'm not sure that you actually have spurious values though. The it's possible that the square root gave solvelib::checkSolutions trouble.

You may have thought that you had spurious values when you checked because you weren't outputting the variables correctly. You specify that solve solve for x, y, l, r (in that order), but then you name the output variables as sol_l, sol_r, sol_x, sol_y (different order). You must use the same order as `solve cannot guess bases on the names of your variables.

Your code:

R=30;
x0=-R;
y0=0;
l0=R/100;
t0=1.2;
t=0.7071;
r0=R-l0/2;
a=[1.78E-05 3.39E-04 0.0104 -0.05791 -16.36];

[sol_x,sol_y,sol_l,sol_r] = solve(l^2 == (x-x0)^2+(y-y0)^2, ...
                                  r == abs((x+x0)/2), ...
                                  poly2sym(a) == y, ...
                                  l*r*t == l0*r0*t0, ...
                                  x,y,l,r, 'Real', true)
% Check
sol_l2.^2 - (sol_x2-x0).^2+(sol_y2-y0).^2
sol_r - abs((sol_x+x0)/2)
[subs(poly2sym(a),x,sol_x(1));subs(poly2sym(a),x,sol_x(2));...
 subs(poly2sym(a),x,sol_x(3));subs(poly2sym(a),x,sol_x(4))]-sol_y;
sol_l2.*sol_r2*t - l0*r0*t0

The check returns small values close zero.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top