My needs are shown in the picture is.
**1. Calculate the equation after a straight line and an ellipse are simultaneous (eliminate x)
Calculating the discriminant of simultaneous equations
Calculate Veda of simultaneous equations (x1+x2, x1 x2, y1+y2, y1 y2, x1 x2+y1 y2, x1 y2+x2 y1)
Calculate the chord AB length where the ellipse intersects the line**
I wrote some tedious code myself, and I think it can be optimized.
It is better to use the symbols in the picture to represent the corresponding results.
Such as:
x1+x2=-((2 a^2 k m)/(b^2 + a^2 k^2))
and so on
How can we further optimize it? Thank you!
The code is as follows:
eqns = {x^2/a^2 + y^2/b^2 == 1, y == k x + m};
polyex = Apply[Subtract, eqns, {1}];
polys = Numerator[Together[Apply[Subtract, eqns, {1}]]];
xpoly = Collect[Resultant[polys[[1]], polys[[2]], y], x]
discx = Factor[Discriminant[xpoly, x]] (*discriminant*)
frist = Solve[eqns, {x, y}] // FullSimplify;
{{x1, y1}, {x2, y2}} = {x, y} /. frist;
second = {x1 + x2, x1 x2, y1 + y2, y1 y2} // FullSimplify
thrid = {x1 x2 + y1 y2, x1 y2 + x2 y1} // FullSimplify
slope = -CoefficientList[polyex[[2]], x][[2]]; (*k*)
intercept = -CoefficientList[CoefficientList[polyex[[2]], y][[1]],
x][[1]] ; (*m*)
Chordlength =
FullSimplify[
Sqrt[1 + slope^2] Sqrt[(x1 + x2)^2 - 4 x1 x2]] (*AbsAB*)