TransWikia.com

determine the coefficients of a quadratic equation with "Solve"

Mathematica Asked by asad on May 12, 2021

Assume we want to determine the coefficients (integer) of a quadratic equation by having some information about the input and output values. If I enter the input and output individually before the command Solve, it gives me the correct answer, but I want to give the sequence of out put inside the Solve and get some perhaps different coefficients, it does not work. I give an example:

Clear[a, b, c, x, y, z, d1, d2, d3]

x = 1; d1 = 44; y = 2; d2 = 158; z = 4; d3 = 596;

Solve[{a x^2 + b x + c == d1 && a y^2 + b y + c == d2 && 
a z^2 + b z + c == d3}, {a, b, c}, Integers] // Column

the result is {a -> 35, b -> 9, c -> 0}

Clear[a, b, c, x, y, z, d1, d2, d3]

x = 1; d1 = 37; y = 2; d2 = 132; z = 4; d3 = 568;

Solve[{a x^2 + b x + c == d1 && a y^2 + b y + c == d2 && 
a z^2 + b z + c == d3}, {a, b, c}, Integers] // Column

The result is {a -> 41, b -> -28, c -> 24}.

Now I want to get these two or perhaps more answers with entering a sequence of “d1,d2,d3” ($d1in {37, 44}$, $d2in {132, 144, 154, 156, 158}$, $d3in {497, 568, 588, 595, 596}$) inside the Solve but it does not work. Could you please let me know where is the error:

Clear[a, b, c, x, y, z, d1, d2, d3]

x = 1; y = 3; z = 6; 

Solve[{a x^2 + b x + c == d1 && a y^2 + b y + c == d2 && 
a z^2 + b z + c == d3&&{d1,{37, 44}}&&{d2,{132, 144, 154, 156, 158}}&&{d3,{497, 568, 588, 595, 596}}}, {a, b, c}, Integers] // Column

If I do all the cases individually I get

{a -> 41, b -> -28, c -> 24}, 
{a -> 35, b -> 2, c -> 0}, 
{a -> 30,  b -> 27, c -> -20},
{a -> 29, b -> 32, c -> -24}, 
{a -> 28, b -> 37,  c -> -28}, 
{a -> 48, b -> -56, c -> 52}, 
{a -> 42, b -> -26,  c -> 28}, 
{a -> 37, b -> -1, c -> 8}, 
{a -> 36, b -> 4,  c -> 4}, 
{a -> 35, b -> 9, c -> 0}

But I like to get them once I run the command.

P.S. Note that it is not necessarily always has solution with a given set of “d1,d2,d3”, however I need to know this by once not trial and error for all combinations of the elements of $d1,d2,d3$.

2 Answers

Here is how I would approach this. I modified your acceptable d1 values so that there would be a couple of solutions rather than an empty set.

Clear[a, b, c, x, y, z, d1, d2, d3]

x = 1; y = 3; z = 6;

elem = Or @@@ 
   Thread /@ Thread[
     {d1, d2, d3} ==
       {{2, 6, 37, 44}, {132, 144, 154, 156, 158}, {497, 568, 588, 595, 596}}
    ];

Reduce[{a x^2 + b x + c == d1 && a y^2 + b y + c == d2 && a z^2 + b z + c == d3, 
    Sequence @@ elem}, {a, b, c}, Integers] // ToRules // List
{{d1 -> 2, d2 -> 158, d3 -> 497, a -> 7, b -> 50, c -> -55},
 {d1 -> 6, d2 -> 158, d3 -> 596, a -> 14, b -> 20, c -> -28}}

Correct answer by Mr.Wizard on May 12, 2021

Solve first and then do the replacements?

soln = 
 First[Solve[{a*x^2 + b*x + c == d1, a*y^2 + b*y + c == d2, 
    a*z^2 + b*z + c == d3, x == 1, y == 3, z == 6}, {a, b, c, x, y, 
    z}]]

(* Out[135]= {a -> 1/30 (3 d1 - 5 d2 + 2 d3), 
 b -> 1/30 (-27 d1 + 35 d2 - 8 d3), c -> 1/5 (9 d1 - 5 d2 + d3), 
 x -> 1, y -> 3, z -> 6} *)

replacements = 
  Map[Thread[{d1, d2, d3} -> #] &, 
   Flatten[Outer[
     List, {37, 44}, {132, 144, 154, 156, 158}, {497, 568, 588, 595, 
      596}], 2]];

{a, b, c} /. soln /. replacements

(* Out[137]= {{89/6, -(71/6), 34}, {587/30, -(923/30), 241/5}, {209/
  10, -(361/10), 261/5}, {641/30, -(1139/30), 268/5}, {643/
  30, -(1147/30), 269/5}, {77/6, 13/6, 22}, {527/30, -(503/30), 181/
  5}, {189/10, -(221/10), 201/5}, {581/30, -(719/30), 208/5}, {583/
  30, -(727/30), 209/5}, {67/6, 83/6, 12}, {159/10, -(51/10), 131/
  5}, {517/30, -(313/30), 151/5}, {177/10, -(123/10), 158/5}, {533/
  30, -(377/30), 159/5}, {65/6, 97/6, 10}, {467/30, -(83/30), 121/
  5}, {169/10, -(81/10), 141/5}, {521/30, -(299/30), 148/5}, {523/
  30, -(307/30), 149/5}, {21/2, 37/2, 8}, {457/30, -(13/30), 111/
  5}, {497/30, -(173/30), 131/5}, {511/30, -(229/30), 138/5}, {171/
  10, -(79/10), 139/5}, {233/15, -(272/15), 233/5}, {304/
  15, -(556/15), 304/5}, {108/5, -(212/5), 324/5}, {331/15, -(664/15),
   331/5}, {332/15, -(668/15), 332/5}, {203/15, -(62/15), 173/
  5}, {274/15, -(346/15), 244/5}, {98/5, -(142/5), 264/5}, {301/
  15, -(454/15), 271/5}, {302/15, -(458/15), 272/5}, {178/15, 113/15, 
  123/5}, {83/5, -(57/5), 194/5}, {269/15, -(251/15), 214/5}, {92/
  5, -(93/5), 221/5}, {277/15, -(283/15), 222/5}, {173/15, 148/15, 
  113/5}, {244/15, -(136/15), 184/5}, {88/5, -(72/5), 204/5}, {271/
  15, -(244/15), 211/5}, {272/15, -(248/15), 212/5}, {56/5, 61/5, 103/
  5}, {239/15, -(101/15), 174/5}, {259/15, -(181/15), 194/5}, {266/
  15, -(209/15), 201/5}, {89/5, -(71/5), 202/5}} *)

Answered by Daniel Lichtblau on May 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP