csn899
(Lee Tao)
November 1, 2021, 11:21am
1
Collect[SubtractSides[
Eliminate[{x^2/a^2 + y^2/b^2 == 1, y == k x + m}, y], x], x]
SubtractSides[%]
MultiplySides[%, a^2, GenerateConditions → False]
Collect[%, x, Apart]
The above code makes the univariate quadratic equation obtained by combining the binary quadratic equation and the binary quadratic equation, and then how to automatically calculate its discriminant and Weida (the sum of two roots and the product of two roots).
csn899
(Lee Tao)
November 1, 2021, 11:50am
2
The requirements are mainly as follows:
input two equations for simultaneous calculation. as follows:
x^2/a^2 - y^2/b^2 == 1, y == k x + m
Automatically generate simultaneous equations. as follows:
a^2 b^2 + a^2 m^2 + 2 a^2 k m x + (-b^2 + a^2 k^2) x^2 == 0
Automatically calculate the discriminant of generating equation. as this
4 a^2 b^2 (b^2 - a^2 k^2 + m^2)
Automatically calculate the Veda of the generated equation
x1+x2=-((2 a^2 k m)/(-b^2 + a^2 k^2))
x1 x2=(a^2 (b^2 + m^2))/(-b^2 + a^2 k^2)
csn899
(Lee Tao)
November 1, 2021, 2:15pm
3
I made this by myself. I feel too tedious and troublesome. How to optimize the results so that they can be output sequentially at once.
csn899
(Lee Tao)
November 3, 2021, 2:07am
4
The above method step code is more and messy, and the results are displayed one at a time, is there any way to integrate to be able to output all the results at one time after input?
Thank you.
danl
(Daniel Lichtblau)
November 4, 2021, 2:12pm
5
It is straightforward to eliminate one variable using Resultant. Then use Discriminant and CoefficientList to get the requested values.
eqns = {x^2/a^2 - y^2/b^2 == 1, y == k x + m};
polys = Apply[Subtract, eqns, {1}]
(* Out[575]= {-1 + x^2/a^2 - y^2/b^2, -m - k x + y} *)
xpoly = Resultant[polys[[1]], polys[[2]], y];
discx = Discriminant[xpoly, x]
(* Out[578]= -((4 (-b^2 + a^2 k^2 - m^2))/(a^2 b^2)) *)
coeffs = CoefficientList[xpoly, x]
(* Out[579]= {-1 - m^2/b^2, -((2 k m)/b^2), 1/a^2 - k^2/b^2} *)
{rootproduct, rootsum} = Together[Most[coeffs]/Last[coeffs]]
(* Out[581]= {(a^2*(b^2 + m^2))/(-b^2 + a^2*k^2), -((2*a^2*k*m)/(b^2 - a^2*k^2))} *)
csn899
(Lee Tao)
November 6, 2021, 1:04pm
6
Thank you!
But I don’t understand the meaning of the answer obtained by this operation, which is different from the answer I want to get.
danl
(Daniel Lichtblau)
November 6, 2021, 3:30pm
7
My last line was wrong because I forgot the ordering used by CoefficientList (a function I have worked on, no less). I corrected it now.
csn899
(Lee Tao)
November 6, 2021, 11:44pm
8
Thank you very much!
The result is equivalent to what I want.
Can the result be more optimized?
The simultaneous equation requires the coefficient of quadratic term, the coefficient of primary term and the constant term are integral, not fractional.
On this basis, the discriminant and Veda are calculated.
for example:
coeffs = CoefficientList[xpoly, x]
(* Out[579]= {-1 - m^2/b^2, -((2 k m)/b^2), 1/a^2 - k^2/b^2} *)
I want the result as follow:
a^2 b^2 + a^2 m^2 , 2 a^2 k m ,(-b^2 + a^2 k^2)
the result of discriminant as well
Thank you again!
danl
(Daniel Lichtblau)
November 7, 2021, 3:21pm
9
You can get something along those lines by clearing denominators in the input. This can be done as below.
polys = Numerator[Together[Apply[Subtract, eqns, {1}]]]
Thanks very much!
eqns = {x^2/a^2 + y^2/b^2 == 1, y == k x + m};
(*polys=Apply[Subtract,eqns,{1}]*)
polys = Numerator[Together[Apply[Subtract, eqns, {1}]]]
(*Out[575]={-1+x^2/a^2-y^2/b^2,-m-k x+y}*)
xpoly = Resultant[polys[[1]], polys[[2]], y];
discx = Discriminant[xpoly, x]
(*Out[578]=-((4 (-b^2+a^2 k^2-m^2))/(a^2 b^2))*)
coeffs = CoefficientList[xpoly, x]
(*Out[579]={-1-m^2/b^2,-((2 k m)/b^2),1/a^2-k^2/b^2}*)
{rootproduct, rootsum} = Together[Most[coeffs]/Last[coeffs]]
(*Out[581]={(a^2*(b^2+m^2))/(-b^2+a^2*k^2),-((2*a^2*k*m)/(b^2-a^2*k^2)\
)}*)
Chordlength = Simplify[Sqrt[rootsum^2 - 4 rootproduct]]
csn899
(Lee Tao)
November 8, 2021, 2:56am
11
Chordlength = Simplify[Sqrt[rootsum^2 - 4 rootproduct]]
i want to calculate the cchord length
the above code should be :
Chordlength = Simplify[Sqrt[1+k^2] Sqrt[rootsum^2 - 4 rootproduct]]
But the code must have a certain generality. K is the coefficient in front of x of the linear equation entered earlier. When the straight line varies according to the input value, how to replace the k value in the code for calculating the chord length with the corresponding input value?
Thank you!
csn899
(Lee Tao)
November 8, 2021, 11:37am
12
slope = Coefficient[CoefficientList[polys[[2]], y], x, 1]
The problem is how to extract the linear equation y==kx+m that was originally input.
Coefficient k before x
the code above output the array
csn899
(Lee Tao)
November 8, 2021, 1:18pm
13
Veda still has an error in the calculation result, the result of the product of the two roots is correct, and the result of the sum of the two roots is wrong, because the sum of the two roots is equal to the opposite number of the coefficient of the first term than the coefficient of the second term, and the running result is one minus sign less.
csn899
(Lee Tao)
November 8, 2021, 1:42pm
14
I tried to write what I asked for myself.
By adding a formula for calculating the chord length, it is OK to extract the coefficient k in front of the linear equation x, that is, the slope.
Do not know how to optimize?
First of all, I would like to ask the expert to help me correct the result of Weida. Thank you!
the code as follows:
csn899
(Lee Tao)
November 8, 2021, 2:23pm
16
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 = Resultant[polys[[1]], polys[[2]], y]
discx = Discriminant[xpoly, x]
slope = -CoefficientList[polyex[[2]], x][[2]]
coeffs = CoefficientList[xpoly, x]
{rootproduct, rootsum} = Together[Most[coeffs]/Last[coeffs]]
Chordlength =
Simplify[Sqrt[1 + slope^2] Sqrt[rootsum^2 - 4 rootproduct]]
csn899
(Lee Tao)
November 9, 2021, 12:31am
17
eqns = {x^2/4 + y^2/2 == 1, y == (1/2) x + 1};
polyex = Apply[Subtract, eqns, {1}]
polys = Numerator[Together[Apply[Subtract, eqns, {1}]]]
xpoly = Resultant[polys[[1]], polys[[2]], y]
discx = Factor[Discriminant[xpoly, x]]
slope = -CoefficientList[polyex[[2]], x][[2]]
coeffs = CoefficientList[xpoly, x]
(*{rootproduct,rootsum}=Together[Most[coeffs]/Last[coeffs]]*)
{rootsum,
rootproduct} = {-CoefficientList[xpoly, x][[2]]/Last[coeffs],
CoefficientList[xpoly, x][[1]]/Last[coeffs]}
Chordlength =
Simplify[Sqrt[1 + slope^2] Sqrt[rootsum^2 - 4 rootproduct]]
csn899
(Lee Tao)
November 9, 2021, 1:19am
19
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 = Resultant[polys[[1]], polys[[2]], y]
discx = Factor[Discriminant[xpoly, x]] (*discriminant*)
(*CoefficientList[polyex[[2]],y]*)
slope = -CoefficientList[polyex[[2]], x][[2]] (*k*)
intercept = -CoefficientList[CoefficientList[polyex[[2]], y][[1]],
x][[1]] (*m*)
coeffs = CoefficientList[xpoly, x]
(*{rootproduct,rootsum}=Together[Most[coeffs]/Last[coeffs]]*)
{rootsum,
rootproduct} = {-CoefficientList[xpoly, x][[2]]/Last[coeffs],
CoefficientList[xpoly, x][[1]]/Last[coeffs]} (*x1+x2;x1x2*)
{yrootsum, yrootproduct} =
Simplify[Together[{slope*rootsum + 2 intercept,
slope^2*rootproduct + intercept*slope*rootsum +
intercept^2}]] (* y1+y2;y1y2*)
Simplify[rootproduct + yrootproduct] (*x1x2+y1y2*)
Simplify[2 slope rootproduct + intercept rootsum] (*x1y2+x2y1*)
Chordlength =
Simplify[Sqrt[1 + slope^2] Sqrt[
rootsum^2 - 4 rootproduct]] (*AbsAB*)
csn899
(Lee Tao)
November 10, 2021, 11:35pm
20
How to optimize the above code?