How to make a Dynamic Calculator to solve a quadratic equation?

Taking my first steps in the world of Mathematica Programming.

The aim of my program was to modify Wolfram's dynamic calculator
(which performs an addition subtraction and a product - in response to the user inputting two values used to perform these operations)
to now take three input and display on the three outputs:

[1] the quadratic equation to be solved
[2] the roots of this quadratic equation
[3] the discriminant of this equation

The three things (in red text) which you have to input are:

first input box is coefficient a
second input box is coefficient b
third input box is coefficient c

These coefficients represent a,b and c in the quadratic equation $ax^2 + bx +c$

So the Wolfram Demonstration & My attempt (the code below) look like this: http://www.controlmanchester.com/2013/08/01/quadratic-equation-images/

The code for the original program is available here: http://reference.wolfram.com/mathematica/example/ConstructADynamicCalculator.html

This is the code that I have written (modified really):

 DynamicModule[
{a = 0, b = 0, c = 0},
Deploy[
Style[
Panel[
Grid[
Transpose[
{
{
Style["input a ", Red],
Style["input b", Red],
Style["input c", Red],
"here is the equation",
"here is the value of the discriminant",
"here are the roots"},

{InputField[Dynamic[a], Number],
InputField[Dynamic[b], Number],
InputField[Dynamic[c], Number],
InputField[Dynamic[a*x^2 + b*x + c],Enabled -> False],
InputField[Dynamic[b]^2 - (4*Dynamic[a]*Dynamic[c]) , Enabled -> False],
InputField[Dynamic[a b], Enabled -> False]}
}
]
, Alignment -> Right]
, ImageMargins -> 10]
,
DefaultOptions -> {InputField -> {ContinuousAction -> True,
FieldSize -> {{5, 30}, {1, Infinity}}}}]
]
]


I have discovered, via trial and error, that within an input field I cannot simply try something like
Solve[x^2 + a x + 1 == 0, x] or Roots[ ].

I think this is where the heart of my problem lies.

At the moment the variables I put in do propagate down and show the coefficients of the quadratic, but I cannot get any further with it.

Any help, or guidance to things I should read are most welcome.

Many Thanks, David

p.s. I have seen from the answer by Mike Honeychurch that I have not described the problem as clearly as possible. I have edited the post :) I hope this makes my problem easier to understand

• "First steps in the world of Mathematica Programming" and "DynamicModule..." — yikes! :) – rm -rf Aug 1 '13 at 19:48
• I think Nasser is right - Manipulate is a better place to start than DynamicModule – cormullion Aug 2 '13 at 8:31

Manipulate[
Grid[
{
{"Equation", Row[{u, " = 0"}]},
{"Solutions", Solve[u == 0, x]},
{"Roots", Roots[u == 0, x]},
{"Discriminant", Discriminant[u, x]}
}, Alignment -> Left],
{{u, x^2 + 2 x + 1}},
BaseStyle -> FontSize -> 16]


• +1 this is exactly what I was trying to write but in far less code. I have learned something about the complexities of dynamic vs manipulate. Thanks. – AugustCrawl Aug 2 '13 at 14:26
• :) Cool, and thanks. Even experienced users mutter under their breath about the complexities of Dynamic and DynamicModule... – cormullion Aug 2 '13 at 14:34

Sorry but it is unclear to me what you want to be able to type in the input fields and what you want to see. If you use InputField[expr, Hold[Expression]] you can type Solve[...]. Here is an example (which is why I have made this an "answer" --though it is not really an answer 'cause I am unsure what you want -- rather than a comment).

DynamicModule[{z = Null},

Column[{

InputField[Dynamic[z], Hold[Expression]],
Dynamic[ReleaseHold[z]]

}]
]


or

DynamicModule[{z = Null},

Column[{

InputField[Dynamic[z], Hold[Expression]],
Spacer[{0, 15}],
Dynamic[
If[Head[ReleaseHold[z]] === Equal, Solve[ReleaseHold[z], x],
Spacer[0]]]

}]
]


• Thank you for your Answer Mike. I have modified the question to make it more readable. I have also linked to a website I administrate where you can see images of both the output of the wolfram example and of the one I have written. @MikeHoneychurch – AugustCrawl Aug 1 '13 at 23:05