Tag Archives: expressions

My first program – quadratic equation

Lets write our first program with Calcpad. Most programming languages usually start with “Hello world!”, but for Calcpad, there is nothing much to do, except to write the text in quotes:

"Hello world from Calcpad!"

Then press Enter and the text will appear in the output.

So, let’s do something more useful and solve a real problem. The quadratic equation is simple enough to start with.

All you need to do is to enter the formulas and the text in the “Script” box on the left. Then press Enter or the orange arrow and you will get the results in the “Output” box on the right:

Quadratic equation

Bellow, you can copy the source code and try it by yourself:

"Quadratic equation:
'a*x^2 + b*x + c = 0
a = 3 ', ' b = 4 ', ' c = -5
'Discriminant - ' D = b^2 - 4*a*c
x_1 = (-b - sqr(D))/(2*a)
x_2 = (-b + Sqr(D))/(2*a)

All comments must be enclosed in quotes: double quotes for “titles” and single quotes for ‘simple text’. In this example, "Quadratic equation is a title and 'Discriminant - ' is text. The closing quote can be omitted, if there is nothing further on the line.

Everything outside the quotes is assumed to be math expressions.  Normally, each expression should be on a new line. If they are several expressions on the same line, they must be separated by comments, e.g. 

a = 3 ', ' b = 4 ', ' c = -5

Expressions are defined by using the commonly accepted mathematical notation: numbers, variables, operators “^ / \ % * - + ≡ ≠ ≤ ≥ =” and standard mathematical functions. A short description of the available syntax is initially displayed in the output box. For more information, please check the user manual:

http://calcpad.net/Help/Expressions

The output is automatically formatted in a professional looking Html report, ready for printing:

  • the sqr function is replaced by the square root symbol;
  • the “^” operator is formatted as superscript;
  • underscores “_” in variable names are replaced by subscripts etc.

All formulas are rendered into the calculation report. Additionally, Calcpad can show variable substitutions, so you can check every value in the output. This is a great advantage over Excel spreadsheets, where the actual formulas are hidden in the cells. It is important for structural calculations to be presented in a way that allows them to be easily followed and verified by the approving authorities.

In the next publication we will add more features to our quadratic equation program.