Reference: Difference between revisions

From iMath
Jump to navigation Jump to search
No edit summary
Line 75: Line 75:
Create an integral from the lower bound to the upper bound. The function can then be symbolically evaluated with the <code>SIMPLIFY</code> keyword. If the upper bound is a number or a variable then the curly braces around it can be omitted. Example: <code>INT FROM x = -%pi to %pi { sin(x) } dx</code>
Create an integral from the lower bound to the upper bound. The function can then be symbolically evaluated with the <code>SIMPLIFY</code> keyword. If the upper bound is a number or a variable then the curly braces around it can be omitted. Example: <code>INT FROM x = -%pi to %pi { sin(x) } dx</code>


==== <code>LHS ( equation )<code> ====
==== <code>LHS ( equation )</code> ====
Gets the left hand side of the equation.
Gets the left hand side of the equation.


==== <code>NUMVAL ( expression )<code> ====
==== <code>NUMVAL ( expression )</code> ====
Try to find a numeric value (without units) for the expression from any equations defined previously in the document. Gives an error if the expression does not evaluate to a number.  
Try to find a numeric value (without units) for the expression from any equations defined previously in the document. Gives an error if the expression does not evaluate to a number.  


==== <code>NUMVALWITH ( expression, expression; expression; ... )<code> ====
==== <code>NUMVALWITH ( expression, expression; expression; ... )</code> ====
Try to find a numeric value for the expression from any equations defined previously in the document, plus the equations given as the second argument. Gives an error if the expression does not evaluate to a number.  
Try to find a numeric value for the expression from any equations defined previously in the document, plus the equations given as the second argument. Gives an error if the expression does not evaluate to a number.  


==== <code>QUANTITY ( expression )<code> ====
==== <code>QUANTITY ( expression )</code> ====
Try to find a quantity (number with optional units) for the expression from any equations defined previously in the document. Gives an error if the expression does not evaluate to a quantity.  
Try to find a quantity (number with optional units) for the expression from any equations defined previously in the document. Gives an error if the expression does not evaluate to a quantity.  


==== <code>QUANTITYWITH ( expression, expression; expression; ... )<code> ====
==== <code>QUANTITYWITH ( expression, expression; expression; ... )</code> ====
Try to find a quantity (number with optional units) for the expression from any equations defined previously in the document, plus the equations given as the second argument. Gives an error if the expression does not evaluate to a quantity.  
Try to find a quantity (number with optional units) for the expression from any equations defined previously in the document, plus the equations given as the second argument. Gives an error if the expression does not evaluate to a quantity.  


==== <code>REV ( equation )<code> ====
==== <code>REV ( equation )</code> ====
Reverse the left hand side and the right hand side of the equation  
Reverse the left hand side and the right hand side of the equation  


==== <code>RHS ( equation )<code> ====
==== <code>RHS ( equation )</code> ====
Gets the right hand side of the equation  
Gets the right hand side of the equation  


==== <code>SIMPLIFY ( equation, { "simplification"; "simplification"; ... } )<code> ====
==== <code>SIMPLIFY ( equation, { "simplification"; "simplification"; ... } )</code> ====
Simplifies both sides of the equation according to the simplifications given in a list. Possible values are:  
Simplifies both sides of the equation according to the simplifications given in a list. Possible values are:  
* <code>expand</code> Fully expands all expressions, including function arguments.  
* <code>expand</code> Fully expands all expressions, including function arguments.  
Line 109: Line 109:
* <code>integrate</code> Symbolically integrates any integrals in the expression as far as possible.  
* <code>integrate</code> Symbolically integrates any integrals in the expression as far as possible.  


==== <code>SOLVE ( equation, variable, solution )<code> ====
==== <code>SOLVE ( equation, variable, solution )</code> ====
Solve the equation for the variable. If there are several possible solutions (e.g. for a quadratic equation), you can specify which one you want in the third argument. Note that this argument is not optional, so you must specify 1 for a linear equation.
Solve the equation for the variable. If there are several possible solutions (e.g. for a quadratic equation), you can specify which one you want in the third argument. Note that this argument is not optional, so you must specify 1 for a linear equation.


==== <code>SUBST ( expression, equation OR {equation; equation; ...} )<code> ====
==== <code>SUBST ( expression, equation OR {equation; equation; ...} )</code> ====
Substitute the equation or the list of equations in the expression. All substitutions will be done in parallel, which means that a list of equations like <code>{ x = y; y = z}</code> might not have the desired effect (consider using <code>SUBSTC</code> instead).  
Substitute the equation or the list of equations in the expression. All substitutions will be done in parallel, which means that a list of equations like <code>{ x = y; y = z}</code> might not have the desired effect (consider using <code>SUBSTC</code> instead).  


==== <code>SUBSTC ( expression, equation OR {equation; equation; ...} )<code> ====
==== <code>SUBSTC ( expression, equation OR {equation; equation; ...} )</code> ====
Substitute the equation or the list of equations in the expression. The substitutions will be done in the order you specifiy them, so a list of equations like <code>{ x = y; y = z}</code> will have the effect of substituting x=z.  
Substitute the equation or the list of equations in the expression. The substitutions will be done in the order you specifiy them, so a list of equations like <code>{ x = y; y = z}</code> will have the effect of substituting x=z.  


==== <code>SUBSTV ( expression, variable = vector )<code> ====
==== <code>SUBSTV ( expression, variable = vector )</code> ====
Substitute a vector of expressions in the expression. The result will be a vector. This is mostly useful for specifying values to the <code>CHART</code> keyword.  
Substitute a vector of expressions in the expression. The result will be a vector. This is mostly useful for specifying values to the <code>CHART</code> keyword.  


==== <code>SUM FROM variable = expression TO { expresssion} { expression }<code> ====
==== <code>SUM FROM variable = expression TO { expresssion} { expression }</code> ====
Create a sum function summing up the expression from the lower bound to the upper bound. The function can then be symbolically evaluated with the <code>SIMPLIFY</code> keyword. If the upper bound is a number or a variable then the curly braces around it can be omitted.  
Create a sum function summing up the expression from the lower bound to the upper bound. The function can then be symbolically evaluated with the <code>SIMPLIFY</code> keyword. If the upper bound is a number or a variable then the curly braces around it can be omitted.  


==== <code>TSERIES ( expression, variable = expression, nth )<code> ====
==== <code>TSERIES ( expression, variable = expression, nth )</code> ====
Create a Taylor series of nth grade for the expression around the given point.  
Create a Taylor series of nth grade for the expression around the given point.  


==== <code>UNIT ( expression )<code> ====
==== <code>UNIT ( expression )</code> ====
Try to find a quantity (number with optional units) for the expression from any equations defined previously in the document, and then get the units of this result. Gives an error if the expression does not evaluate to a quantity.  
Try to find a quantity (number with optional units) for the expression from any equations defined previously in the document, and then get the units of this result. Gives an error if the expression does not evaluate to a quantity.  


==== <code>UNITWITH ( expression, expression; expression; ... )<code> ====
==== <code>UNITWITH ( expression, expression; expression; ... )</code> ====
Try to find a quantity (number with optional units) for the expression from any equations defined previously in the document, plus the equations given as the second argument, and then get the units of this result. Gives an error if the expression does not evaluate to a quantity.  
Try to find a quantity (number with optional units) for the expression from any equations defined previously in the document, plus the equations given as the second argument, and then get the units of this result. Gives an error if the expression does not evaluate to a quantity.  


==== <code>VAL ( expression )<code> ====
==== <code>VAL ( expression )</code> ====
Try to find a numeric value for the expression from any equations defined previously in the document.  
Try to find a numeric value for the expression from any equations defined previously in the document.  


==== <code>VALWITH ( expression, expression; expression; ... )<code> ====
==== <code>VALWITH ( expression, expression; expression; ... )</code> ====
Try to find a numeric value for the expression from any equations defined previously in the document, plus the equations given as the second argument. These will be removed again after the value search, so they have no effect on the rest of the document.  
Try to find a numeric value for the expression from any equations defined previously in the document, plus the equations given as the second argument. These will be removed again after the value search, so they have no effect on the rest of the document.  



Revision as of 18:55, 23 December 2013

It is recommended to always use the iMath menus to create or modify iFormulas. Nevertheless, sometimes it will be necessary to fine-tune equations by editing them directly.

All iMath commands start with the string %%ii at the beginning of a line, which will be interpreted as a comment by Openoffice. When the document is recalculated, iMath parses the string and generates the formula that is displayed. The generated lines are marked by %%gg at the end of the line. Editing such a line makes no sense because it will be deleted at the next recalculation! Always modify the %%ii lines if you want to tweak an iFormula. Formulas may also have lines without either %%ii or %%gg, these will not be touched by iMath.

There is also a reference section integrated into the Office help. Press F1 and enter "iFormula" into the Index tab of the help.

Elements

The following elements can be part of an iFormula definition string

  • symbol

The name of a mathematical symbol or function, e.g. x or a_n

  • unit

The name of a physical unit, either preceded by a percent sign or enclosed in quotation marks, e.g. %meter or "meter"

  • expression

A mathematical expression in Openoffice math format

  • equation

A kind of expression which has the form expression1 = expression2

  • vector = expression1 : expression2 : expression3

A vector of expressions where expression1 is the first element, expression2 the second element and the optional expression3 the step. By default the given interval will be subdivided into 20 steps, so for example x = 1:20 will give a vector containing the integer numbers from 1 to 20.

  • symbol [ number ] or symbol [ number, number ]

Accesses an element of a matrix.

  • #label#

A equation label, used to reference a previously defined equation. The label MUST be enclosed in hash signs.

  • list = { element; element; ... }

A list of other elements, enclosed in parentheses and separated by semicolons

  • *

If the asterisk is given, then the output of this line is supressed, which is useful for hiding intermediate calculations.

  • { option; option; ... }

The options can be any of those described for the OPTIONS keyword. It is not necessary to specify options (you need to leave away the brackets, too, if you don't).

Commands

After the initial %%ii, several groups of commands are possible.

Definitions

iMath allows you to define equations, units and functions, and to evaluate expressions.

{ options } EXDEF expression

Create an expression. This keyword is most frequently used with VAL to find the values of a symbol or an expression, e.g. EXDEF VAL(y).

#label# { options } EQDEF * expression

Define an equation. The expression most be of the form expression1 = expression2. For the special case of the equation label starting with lib:, the equation will not be erased by CLEAREQUATIONS. This is useful for building a library of generic equations, as for example in the file substitutions.imath.

#label# { options } CONSTDEF * expression

Define a constant. The expression most be of the form variable = expression, and the expression must evaluate to a quantity (a numeric with or without units). Constants are not erased by CLEAREQUATIONS. This makes it possible to specify general constants only once in the file and reuse them for several different calculations.

#label# { options } FUNCDEF * funcname(args) = expression

Define an equation that can be used to find the value of a user-defined function. The function must first have been declared with FUNCTION.

FUNCTION { hints, symbol, expression }

Declare a user-defined function. symbol is the name of the function. The expression declares the arguments of the function and can be either a single symbol or a list of symbols. The way that iMath treats this function can be influenced by function hints:

  • none: No function hints (must be used because iMath requires three arguments to the FUNCTION declaration
  • lib: A library function: It will not be affected by CLEAREQUATIONS
  • trig: For trigonometric functions. Tells iMath that this function will get special treatment when printing (e.g. <math>sin^2 x</math> instead of <math>(sin x)^2</math>)
  • expand: The function is to be expanded immediately. Useful for functions that are really abbreviations, e.g. square(x) will be expanded to <math>x^2</math>
  • nobracket: The function does not require brackets around the argument (e.g. sqrt(x) is printed as <math>root x</math>)
  • defdiff: Differentiate the definition of the function, not the function itself

UNITDEF { "unitname", symbol = expression }

Defines a new unit. The symbol is the name of the unit, this must begin with a percent sign % to distinguish it from a variable name. The expression defines the unit in terms of units already known to iMath. If this expression contains data types apart from units, powers of units, numerics, or constants already known to iMath, a warning is issued, but the unit definition is created anyway. The unitname is optional and gives a string to be printed instead of the symbol. This is useful when defining units whose name is not a valid symbol, e.g. inches: UNITDEF{"''", %inch = 0.0254 %m}.

DELETE { #label1#; #label2#; ... }

Removes an equation such that it has no influence on future searches for variable values. Note that the equation is not deleted from the file, but only becomes ineffective (and unaccessible) after the point in the text where the delete statement is.

CLEAREQUATIONS

iMath stores all equations and functions that it encounters. If you want to make a fresh start in your document, use this command.

Symbolic manipulations of expressions

DIFFERENTIATE ( expression, variable, nth )

Differentiate the expression with respect to the variable to the nth grade. Note that if you want to use a differential as part of an expression, you should use the diff() built-in function instead.

INT FROM variable = expression TO { expresssion} { expression } d variable

Create an integral from the lower bound to the upper bound. The function can then be symbolically evaluated with the SIMPLIFY keyword. If the upper bound is a number or a variable then the curly braces around it can be omitted. Example: INT FROM x = -%pi to %pi { sin(x) } dx

LHS ( equation )

Gets the left hand side of the equation.

NUMVAL ( expression )

Try to find a numeric value (without units) for the expression from any equations defined previously in the document. Gives an error if the expression does not evaluate to a number.

NUMVALWITH ( expression, expression; expression; ... )

Try to find a numeric value for the expression from any equations defined previously in the document, plus the equations given as the second argument. Gives an error if the expression does not evaluate to a number.

QUANTITY ( expression )

Try to find a quantity (number with optional units) for the expression from any equations defined previously in the document. Gives an error if the expression does not evaluate to a quantity.

QUANTITYWITH ( expression, expression; expression; ... )

Try to find a quantity (number with optional units) for the expression from any equations defined previously in the document, plus the equations given as the second argument. Gives an error if the expression does not evaluate to a quantity.

REV ( equation )

Reverse the left hand side and the right hand side of the equation

RHS ( equation )

Gets the right hand side of the equation

SIMPLIFY ( equation, { "simplification"; "simplification"; ... } )

Simplifies both sides of the equation according to the simplifications given in a list. Possible values are:

  • expand Fully expands all expressions, including function arguments.
  • expandf Only expand function definition, not arguments.
  • eval Numerically evaluate the equation as far as possible.
  • normal Normalize the equation (see description of GiNaC normal() method for details).
  • collect-common Collect common factors (see description of GiNaC collect_common_factors() method for details).
  • unsafe Does unsafe simplifications, for example sqrt{x^2} => x or \arctan\tan{x} => x. Note that the opposite \tan\arctan{x} => x is not an unsafe evaluation and is thus done automatically (by GiNaC).
  • diff Evaluates differential function diff, thus symbolically calculating differentials as far as possible.
  • sum Evaluates sum functions sum, thus symbolically calculating sums as far as possible.
  • gather-sqrt Gathers single square roots under one root symbol.
  • integrate Symbolically integrates any integrals in the expression as far as possible.

SOLVE ( equation, variable, solution )

Solve the equation for the variable. If there are several possible solutions (e.g. for a quadratic equation), you can specify which one you want in the third argument. Note that this argument is not optional, so you must specify 1 for a linear equation.

SUBST ( expression, equation OR {equation; equation; ...} )

Substitute the equation or the list of equations in the expression. All substitutions will be done in parallel, which means that a list of equations like { x = y; y = z} might not have the desired effect (consider using SUBSTC instead).

SUBSTC ( expression, equation OR {equation; equation; ...} )

Substitute the equation or the list of equations in the expression. The substitutions will be done in the order you specifiy them, so a list of equations like { x = y; y = z} will have the effect of substituting x=z.

SUBSTV ( expression, variable = vector )

Substitute a vector of expressions in the expression. The result will be a vector. This is mostly useful for specifying values to the CHART keyword.

SUM FROM variable = expression TO { expresssion} { expression }

Create a sum function summing up the expression from the lower bound to the upper bound. The function can then be symbolically evaluated with the SIMPLIFY keyword. If the upper bound is a number or a variable then the curly braces around it can be omitted.

TSERIES ( expression, variable = expression, nth )

Create a Taylor series of nth grade for the expression around the given point.

UNIT ( expression )

Try to find a quantity (number with optional units) for the expression from any equations defined previously in the document, and then get the units of this result. Gives an error if the expression does not evaluate to a quantity.

UNITWITH ( expression, expression; expression; ... )

Try to find a quantity (number with optional units) for the expression from any equations defined previously in the document, plus the equations given as the second argument, and then get the units of this result. Gives an error if the expression does not evaluate to a quantity.

VAL ( expression )

Try to find a numeric value for the expression from any equations defined previously in the document.

VALWITH ( expression, expression; expression; ... )

Try to find a numeric value for the expression from any equations defined previously in the document, plus the equations given as the second argument. These will be removed again after the value search, so they have no effect on the rest of the document.



  • READFILE { "path/to/file" }

Open the given file and parse the iMath commands in this file. This command can be used to put common formulas in a file to re-use them. At the moment, the path is operation-system dependent, not a Openoffice URL!

  • CLEAREQUATIONS

iMath stores all equations and functions that it encounters. If you want to make a fresh start in your document, use this command

  • FUNCTION { hints, symbol, expression }

Declare a user-defined function. symbol is the name of the function. The expression declares the arguments of the function and can be either a single symbol or a list of symbols. The way that iMath treats this function can be influenced by function hints:

    • none: No function hints (must be used because iMath requires three arguments to the FUNCTION declaration
    • lib: A library function: It will not be affected by CLEAREQUATIONS
    • trig: For trigonometric functions. Tells iMath that this function will get special treatment when printing (e.g. <math>sin^2 x</math> instead of <math>(sin x)^2</math>)
    • expand: The function is to be expanded immediately. Useful for functions that are really abbreviations, e.g. square(x) will be expanded to <math>x^2</math>
    • nobracket: The function does not require brackets around the argument (e.g. sqrt(x) is printed as <math>root x</math>)
    • defdiff: Differentiate the definition of the function, not the function itself