JuliaSymbolics / Symbolics.jl

Symbolic programming for the next generation of numerical software

Home Page:https://symbolics.juliasymbolics.org/stable/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multiple zeros for linear equation

wangzuodong1997 opened this issue · comments

Hello, I curruntly observed a strange behavior of the symbolic computation. I was trying to find the minimize of a quadratic function, by looking for the unique zero of its derivative (since its derivative is an affine function). But I finally find at least 3 zeros for this affine function. Could you please help me to figure out the problem?

In the following code, the variable is b, and the other variables are considered as parameters. The quadratic function is given by r, its derivative with respect to b is given by dr. At the end of the code, I printed three values which make the affine function equal to zero.

#############################

using Symbolics

let

@variables b, p, c, d, e, f, g, h


a(b) = -c/d - b*e/d

r(b) = c + 2*a(b)*d  + 2*b*e + a(b)*a(b)*f+ 2*a(b)*b*g+ b*b*h
sss(b) = c + 2*a(b)*d  + 2*b*g + a(b)*a(b)*f+ 2*a(b)*b*g+ b*b*h

dr(b) =  Symbolics.derivative(r(b), b)
dssss(b) = Symbolics.derivative(sss(b), b)

c_r = Symbolics.solve_for(dr(b) ~ 0,b)
c_s = Symbolics.solve_for(dssss(b) ~ 0,b)

@show simplify(r(b))

@show simplify(dr(b))

@show simplify(c_r)

@show simplify(c_s)

@show simplify(dr(c_s))
@show simplify(dr(1))
@show simplify(dr(c_r))


end

#####################

And my output is:

simplify(r(b)) = ((c^2)*f - c*(d^2) - 2.0b*c*d*g + 2.0b*c*e*f + (b^2)*(d^2)*h - 2.0(b^2)*d*e*g + (b^2)*(e^2)*f) / (d^2)
simplify(-a1 / (2a2)) = (2.0c*d*g - 2.0c*e*f) / (2((d^2)*h - 2.0d*e*g + (e^2)*f))
simplify(dr(b)) = (-2.0c*d*g + 2.0c*e*f + 2.0b*(d^2)*h - 4.0b*d*e*g + 2.0b*(e^2)*f) / (d^2)
simplify(c_r) = (-c*d*g + c*e*f) / (-(d^2)*h + 2.0d*e*g - (e^2)*f)
simplify(c_s) = (-c*d*g + c*e*f - (d^2)*e + (d^2)*g) / (-(d^2)*h + 2.0d*e*g - (e^2)*f)
simplify(dr(c_s)) = 0
simplify(dr(1)) = 0
simplify(dr(c_r)) = 0