Message Boards Message Boards

0
|
3990 Views
|
20 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Automatically calculate equation's discriminant and Veda?

Posted 2 years ago
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).

POSTED BY: Lee Tao
20 Replies
Posted 2 years ago
eqns = {x^2/a^2 + y^2/b^2 == 1, x == t y + n};

polyex = Apply[Subtract, eqns, {1}]

polys = Numerator[Together[Apply[Subtract, eqns, {1}]]]

xpoly = Collect[Resultant[polys[[1]], polys[[2]], x], y]

discx = Factor[Discriminant[xpoly, y]]   (*discriminant*)

(*CoefficientList[polyex[[2]],y]*)

slope = -CoefficientList[polyex[[2]], y][[2]]    (*k*)

intercept = -CoefficientList[CoefficientList[polyex[[2]], x][[1]], 
    y][[1]]   (*m*)

coeffs = CoefficientList[xpoly, y]

(*{rootproduct,rootsum}=Together[Most[coeffs]/Last[coeffs]]*)

{rootsum, 
  rootproduct} = {-CoefficientList[xpoly, y][[2]]/Last[coeffs], 
  CoefficientList[xpoly, y][[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*)
POSTED BY: Lee Tao
Posted 2 years ago

How to optimize the above code?

POSTED BY: Lee Tao
Posted 2 years ago
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*)
POSTED BY: Lee Tao
Posted 2 years ago

POSTED BY: Lee Tao
Posted 2 years ago
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]]

POSTED BY: Lee Tao
Posted 2 years ago
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]]
POSTED BY: Lee Tao
Posted 2 years ago

enter image description here

POSTED BY: Lee Tao
Posted 2 years ago

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:

POSTED BY: Lee Tao
Posted 2 years ago
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

POSTED BY: Lee Tao

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))} *)
POSTED BY: Daniel Lichtblau
Posted 2 years ago

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.

POSTED BY: Lee Tao
POSTED BY: Daniel Lichtblau
Posted 2 years ago

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!

POSTED BY: Lee Tao

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}]]]
POSTED BY: Daniel Lichtblau
Posted 2 years ago

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]]
POSTED BY: Updating Name
Posted 2 years ago
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!

POSTED BY: Lee Tao
Posted 2 years ago

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.

POSTED BY: Lee Tao
Posted 2 years ago

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.

POSTED BY: Lee Tao
Posted 2 years ago

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.

POSTED BY: Lee Tao
Posted 2 years ago

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)
POSTED BY: Lee Tao
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract