# How does one make a function in Mathematica to later call and solve it?

Such as if I wanted to make a quadratic function, save it, and then later plug in any values of a,b,c in order to solve for x.

This was what I was thinking it would be:

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


Then I want to be able to call it and solve it with arbitrary values

Solve[fQ[1,2,3],x]


I then get this:

Set::write: Tag Plus in 3+2 x+x^2 is Protected.

Solve::eqf: 0 is not a well-formed equation.

Thank you

• @Kuba Meant to have originally wrote that in the question. Has been corrected. – Jwizz Mar 19 '18 at 20:46
• Works fine for me. If in doubt restart your kernel. – george2079 Mar 19 '18 at 20:47
• – David G. Stork Mar 19 '18 at 22:23

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

mySol[1, 2, 3]


$\left\{\left\{x\to -1-i \sqrt{2}\right\},\left\{x\to -1+i \sqrt{2}\right\}\right\}$

Your problem was that you tried to include x, which is irrelevant.

• Thank you so much! – Jwizz Mar 19 '18 at 20:48
• What if with the x^2 and the x I wanted to multiply it by the identity matix 5? I thought it might be: aFunc[a_, b_, c_] := Solve[a x^2*(Times[IdentityMatrix]) + b x*(Times[IdentityMatrix]) + c == 0, x] – Jwizz Mar 19 '18 at 20:51
• However, the output is giving me Out[]={} when I type in aFunc[1,2,3] – Jwizz Mar 19 '18 at 20:52
• If you try to mix matrices (IdentityMatrix[]) and scalars (c) you don't have a valid equation. Moreover, this extension is not part of the question as stated and it is very bad etiquette indeed to ask a question, get a full answer, not accept or up-vote it, and then say... oh... but what I really wanted to ask is... – David G. Stork Mar 19 '18 at 20:54
• Apologies for doing that. It was a two part question. I should have merged into one. – Jwizz Mar 19 '18 at 20:55