Download MATRIXx Getting Started Guide
Transcript
Chapter 3
Xmath
MathScript
MathScript, the language of Xmath, defines statements, constructs,
punctuation, functions (MSFs), commands (MSCs), and objects (MSOs).
You can use MathScript to create your own functions and commands. Open
a text editor, and create a file named cdown.msf (.msf corresponds to
MathScript function) with contents as shown in Example 3-1.
Example 3-1
cdown.msf
#{
cdown counts from the integer input down to 1
and displays the square root of each count.
cdown outputs a vector of the square roots
}#
function [out]=cdown(c)
if is(c,{integer, min=1}) then
out=[];
display "************"
for i=[c:-1:1]
display "SQRT(" + string(i) + ") = " +
string(sqrt(i))
out=[out,sqrt(i)];
endfor
else
error("cdown accepts positive integers only","C",c)
endif
endfunction
Save your file in the current directory for Xmath (or any directory in the
lookup path), and return to Xmath. To see your current lookup path:
show path
To add a new directory to the path:
set path "directory path specification"
Call cdown( ) with valid and invalid inputs:
cdown(5)
cdown(-5)
cdown("what, me worry?")
MATRIXx Getting Started Guide
3-12
ni.com