1
$\begingroup$

Am trying to use the quadratic function while simultaneously multiplying an the identity matrix of 5.

fivemat = {{1, 0, 0, 0, 0}, {0, 1, 0, 0, 0}, {0, 0, 1, 0, 0}, {0, 0, 
   0, 1, 0}, {0, 0, 0, 0, 1}}

mySol[a_, b_, c_] := Solve[a x^2 fivemat + b x fivemat + c == 0, x]

However, when I do the following:

mySol[1,2,3]

It returns:

Out[]={}

Thank you

$\endgroup$
  • $\begingroup$ Question title should really be: "How can I add a scalar to a matrix in Mathematica?" $\endgroup$ – QuantumDot Mar 19 '18 at 23:19
  • $\begingroup$ @QuantumDot changed $\endgroup$ – Jwizz Mar 19 '18 at 23:20
5
$\begingroup$

You are missing a unit matrix:

mySol[a_, b_, c_] := Solve[a x^2 fivemat + b x fivemat + c IdentityMatrix[5] == 0, x]

Now it works:

mySol[1,2,3]

Out[3]={{x -> -1 - I Sqrt[2]}, {x -> -1 + I Sqrt[2]}}
| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you why what exactly happened here? Still lost on why that last one IdentityMatrix[5] was needed? $\endgroup$ – Jwizz Mar 19 '18 at 23:19
  • $\begingroup$ Matrices can only be added to other matrices and not to scalars. $\endgroup$ – QuantumDot Mar 19 '18 at 23:20
  • $\begingroup$ Okay thank you. I was helping a friend solve a problem. He desired the problem to be in essence like this it was written aM^2*I+bM*I+c = 0. But what you are saying here he may have forgotten to add the last matrix. $\endgroup$ – Jwizz Mar 19 '18 at 23:29
  • 1
    $\begingroup$ Since fivemat == IdentityMatrix[5] this is just mySol[a_, b_, c_] := Solve[(a x^2 + b x + c) IdentityMatrix[5] == 0, x] or Solve[(a x^2 + b x + c) == 0, x] $\endgroup$ – Bob Hanlon Mar 19 '18 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.