Math Pro Language

Home Page: http://www.mobile-sciences.com/

Arithmetic Operators: + - * / ^

Relational Operators: < > <= >= = !=

Special Characters:

Caracter Description

[ ] Brackets are used with vectors and matrices.

{ } Curly braces are used with Conditionally execute statements (if).

( ) Parentheses are used to indicate precedence in arithmetic expressions in the usual way. They are used to enclose arguments of functions in the usual way.

= Used in assignment of variables and functions.

Example: x=2, y=x+5, f(x)=x**2+x

Used together with (<) for strings assignment.

Example: str=<mathpro>

Used together with (:) to display the values of variables, functions, and strings.

Example: x:=2, y:=7, f(2):=6, str:=mathpro

; Semicolon. Used to separate statements in multistatement lines. You can have more than one statement on a single line by separating each statement with semicolons.

, Comma used inside brackets .

. Decimal point. 314/100, 3.14, and .314e1 are all the same.

" Used for comments.

: -Used with label identifier

example:

If (x=1){goto label}

x=x+1

label:

-MathPro's write instruction.

example :

x=5;y=6

z=x+y

z:=11

z=2*z

z:=22

MathPro Statements:

Statement Definition Syntax

goto

A goto statement causes your program to unconditionally transfer control to the statement associated with the label specified on the goto statement. goto label_identifier

if

Conditionally execute statements

MathPro evaluates the expression and, if the evaluation yields a logical true or nonzero result, executes one or more MathPro commands denoted here as statements. When you are nesting ifs, each if must be paired with a matching end.

if (expression) { statements }

or

if (expression) {statements1} else {statements2}

repeat

Repeat statements until the boolean expression become true. repeat statements until boolean_expression

Arguments

1. expression

expression is a MathPro expression, usually consisting of variables or smaller expressions joined by relational operators (e.g., count < limit). MathPro evaluates compound expressions from left to right, adhering to operator precedence rules.

2. statements

statements is one or more MathPro statements to be executed only if the expression is true or nonzero.

Examples:

1. Example of (if) statement ( soloution of second order equation: ax2+bx+c=0):

"solving the equation a*x^2+b*x+c=0

"input parameters

a=1; b=1; c=-2; nosol=<noroots>

"algorithm

delta=b*b-4*a*c

if (delta<0){goto noroots)}

if (a!=0){x1=(-b+sqrt(delta))/(2*a);x2=(-b-sqrt(delta))/(2*a)}

else {x1=-c/b;x2=-c/b}

"resulats

x1:=1

x2:=-2

goto exit

noroots:

nosol:=

exit:

2. Example of repeat statement ( factorial of k):

"input value of k

k=4

"algorithm

n=1

m=1

repeat

m=m+1

n=m*n

until m>=k

"result is

n:=24

Built in Functions:

Function Definition Syntax Description

sin Sine of an argument in radians y = sin(x)

asin Inverse sine (arcsine), result in radians y = asin(x)

sinh Hyperbolic sine of an argument in radians y = sinh(x)

cos Cos of an argument in radians y = cos(x)

acos

Inverse cos (arccos), result in radians y = acos(x)

cosh

Hyperbolic cos of an argument in radians y = cosh(x)

tan

Tan of an argument in radians y = tan(x)

atan

Inverse tan (arctan), result in radians y = atan(x)

tanh

Hyperbolic tan of an argument in radians y = tanh(x)

log

Logarithm base 10

log(x)

ln

Logarithm base 2 ln(x)

exp

Exponential y = exp(x)

abs

Absolute value y = abs(x)

sign

Signum function y = sign(x) y = sign(x) returns sign is:

1 if the corresponding element of x is greater than zero

-1 if the corresponding element of x is less than zero

sqrt

Square root y = sqrt(x)

ceil

Round toward infinity y = ceil(x)

floor

Round towards minus infinity y = floor(x)

Bạn đang đọc truyện trên: AzTruyen.Top

Tags: #technology