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


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

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.

  • $\begingroup$ Thank you so much! $\endgroup$ – Jwizz Mar 19 '18 at 20:48
  • $\begingroup$ 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[5]]) + b x*(Times[IdentityMatrix[5]]) + c == 0, x] $\endgroup$ – Jwizz Mar 19 '18 at 20:51
  • $\begingroup$ However, the output is giving me Out[]={} when I type in aFunc[1,2,3] $\endgroup$ – Jwizz Mar 19 '18 at 20:52
  • $\begingroup$ 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... $\endgroup$ – David G. Stork Mar 19 '18 at 20:54
  • $\begingroup$ Apologies for doing that. It was a two part question. I should have merged into one. $\endgroup$ – Jwizz Mar 19 '18 at 20:55

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.