Você está na página 1de 5

" tutor.

txt Tutorial Script File


"
"A scrip file is a text file containing one expression in
"each line. The Evaluator reads a script file and
"evaluates one line at a time transferring data to the
"next line by means of memories or files. This provides
"for means to do complicated and many step calculations.
"As with expressions, a quotation mark is used for
~"commenting or annotating.
"With Scripts you can do any thing that is possible
"to do directly from the Board.
"To run a scrip file from the Evaluator's Board add @
"in front of the file name.
"If you want to run only one expression at a time and
"wait for a prompt, type @@ in front of the file name.
"For example, this tutorial runs using the command
"@@tutor.txt.
"If you have put only one @ and would like the Evaluator
"to wait for a prompt at a specific line, add ~ in front
"of that line like here:
~"This tutorial script file will run the Evaluator
"demonstrating various examples which will teach you to
"write your own script file applications.
"
~"BE CAREFUL AS THERE ARE COMMANDS TO OVERWRITE FILES.
"
"Inspect the tutorial tutor.txt file with the build-in
"text editor to see how it works (load the text file).
"
"To run this tutorial the following example files
"should be present:
"a.dat and b.dat
"During the run of this tutorial several files for
"internal use are generated and deleted when exiting
"the Evaluator.
"
" 1. Getting started
"
"Let's start with the simplest calculation.
"Note that the Evaluator puts 'Script:' in front of each
"non-comment expression read from the file, like this:
2+3 "my first expression.
"To use results in next expressions save them in
"memories or files. To save in a memory, type at the end
"#N where N is the memory location. To retrieve, include
"in a subsequent expression m(N). For example:
2+3#2 "will save 5 in memory 2.
"To read this memory and use it, enter, for example:
m(2)+1
"
" 2. Tables
"
"To obtain a table of x^3 with x from 0 to 8 in 9 steps
"type rng(0,8,9)x^3.
"Important: the board is erased before displaying a table.
rng(0,8,9)x^3
"
"Whenever you use a variable, like x, you get a table.
"Let's examine the expression:
"rng(0,360,361)x;sin(dr(x));cos(dr(x))
"Here sine and cosine functions are calculated for
"degrees (0 to 360).
"x is in degrees from 0 to 360, defined by rng().
"Note that dr() transfers x from degrees to radians.
"We have to use dr() because the sine and cosine
"accept only radians. A semicolon ; is used to
"separate columns.
"
" 3. Saving and reading files
"
"To save in a file use >
"To read tables from a file use <
"For example to save the resulting table to the file
"A.q add the >A.q as in the following
rng(0,360,361)x;sin(dr(x));cos(dr(x))>a.q
"To see that it is really there use a text
"editor or the notepad now (you could use the Evaluator
"but it will stop this tutorial).
"Caution: a white space to the right of > is part of the
"file name.
"To save a number to a file (not a table), write for example
"2+3>b.q and 3+4>b.q will save 5 in b.q
"and 7 in b.q
"To use the saved results input them to z(1,1)
"(z(1,1) is element 1,1 in the file), e.g.:
2+3>b.q
3+4>c.q
z(1,1)#1<b.q
z(1,1)#2<c.q
m(1)+m(2)
"You could skip saving to the files
"and work with m() and # only.
"To compute -pi(3+4)e where pi and e are constant type
-pi(3+4)xp
"
" 4. Substitution
"
"Substitution is simple. It works from left to right.
"For example:
Jack=4+x; Jim=6; Jack+Jim
"
" 5. Solving equations for x
"
"To solve an equation with x as unknown just write it.
"You may want to use rng() to redefine the range
"in which to look for a solution.
"For example rng(-10,10)2x+x^3=1/3
"If there is more than one solution - the program
"will always display the largest solution in the
"range. If you don't use rng(), the default is 0 to 100.
rng(-10,10)2x+x^3=1/3
"
~" 6. Graphs
"
"Graphs can be plotted from expressions or files.
"The Evaluator provides for several methods to display
"the contents of a file as a graph.
"These are p<f, g<f, a<f u<f and w<f, where f is the
"file name and < means to read a file. The file format
"should be compatible with an output table, that is,
"the two first lines are assumed to be headers and
"are ignored and the data is in columns.
"To see the sine column in the above file a.q as a
"function of the x column type:
g<a.q
"To display the 3rd column as a function of the 2nd
"write g<(2)a.q to start with column 2.
"A circle (actually an ellipse) will result:
g<(2)a.q
"To see just the cosine (column 3 in file a.q) type
"y<(3)a.q, this will display the 3rd column as a
"function of the index (row number):
y<(3)a.q
"To see all columns as a function of the first column
"type a<a.q as below:
a<a.q
"
"To display an output table without storing it first in
"a file use grf(n) where n is a number. grf(0) will
"display up to 101 points if rng() is not used.
"For example, to display the log of x, x running from
"0.00001 to 1 through 200 points, type
rng(0.0001,1,200)grf(0)log(x)
"you may use grf with several columns and files.
"See the manual.
"
" 7. Statistics
"
"To do statistics with data from a file use s<file.
"As an example we have prepared the file B.DAT which
"contains school grades. Go ahead and see the contents
"of B.DAT using the note pad.
"The first 2 lines are always ignored by the program
"and may be used as headers. To do statistics on the
"2nd column type:
s<(2)b.dat
"To see the correlation between column 3 (gym) and
" column 4 (history) we type:
s<(3)b.dat
"
"To use the sum of squares in a later calculation
"first, save the results to the file d.q and then read
"the number in the 6th row (1st column) using z(1,6):
s<(3)b.dat>d.q
z(1,6)<d.q
"
"To obtain a 4 slot histogram of column 3
"enter hstgrm(4)<(3)b.dat
"If the number of points is larger then 100 use
"rng(points)hstgrm(slots):
hstgrm(4)<(3)b.dat
"
" 8. Random numbers
"
"r is a random variable in the range 0 to 1.
"We can use r to simulate a
"noisy sine wave. The following will do:
grf(0)sin(x/10)+0.3(0.5-r)
"The Evaluator can estimate uncertainty
"propagation using Monte-Carlo methods.
"As an example, suppose we have the expression
"a+b^2, with a=3(0.2) and b=4(0.1), where the values
"in parentheses are the uncertainties.
"We wish to estimate the uncertainty of a+b^2.
"The following expression
"a=3+0.2(0.5-r)sqrt(12);b=4+0.1(0.5-r)sqrt(12);rng(1000)a+b^2
"will generate output with the right distribution
"because (0.5-r)sqrt(12)
"generates sigma=1 distribution.
"rng(1000) will generate 1000 random points ensuring 3
"percent uncertainty.
"Let's do it and send the output to the file a.q :
a=3+0.2(0.5-r)sqrt(12);b=4+0.1(0.5-r)sqrt(12);rng(1000)a+b^2>a.q
"Now lets calculate the sample standard deviation which is
"included in the statistical output:
s<a.q
"Compare the sample standard deviation to the
"theoretical value 0.8246...
"Let's play more with random numbers.
"The expression 2(0.5-r) will generate a table of
"random numbers +/- 1 around zero. If we sum the
"numbers we get a random walk. Use the variable Ysum to
"sum a file column. The following two steps
" store 401 random numbers in the file a.q and then
"a graph of the random walk is displayed.
rng(401)2(0.5-r)>a.q "step 1
rng(401)grf(0)ysum<a.q "step 2
"
" 9. Number Bases
"
"The Evaluator provides for change of base (2-36) and
"bit wise operations.
"To read a number in a base n type [n] in from of that
"number.
"To display a result in a specific base n, type [n] at
"the end of the expression.
"For example, [2]10001001000100100110101[16] will
" convert from binary to hex bases as follows:
[2]10001001000100100110101[16]
"To read data in a different base n from a file add [n]
"in front of the file-name.
"Let's prepare a binary file and read it later.
"The following expression i;2x^3[2] will write the
" indexed table into the file C.q :
i;2x^3[2]>c.q
"Use the note-pad to look into the file.
"Now let's use it in a graph. grf(0)y<(1)[2]c.q will read
"the data in the 2nd column of c.q and plot it:
grf(0)y<(1)[2]c.q
"
" 10. Bit wise operations
"
"Bit wise operators should be put into [] to prevent
"confusion. For example
" [2]100100010001000 [_and] [2]100101010[2]
"will perform bit wise AND and display the result in
" binary format as follows:
[2]100100010001000 [_and] [2]100101010[2]
"
" 11. Logical Operations
"
"You can test logical expressions.
"The convention is that 0 is FALSE and anything else
"is TRUE.
"For example:
"not( (2 GT 1) and ( 3 [EQ] 7 ) ) should result with 1.
"We used [] otherwise the E in EQ is confused with an
"exponent. Here is another one:
not( (2 gt 1) and ( 3 [eq] 7 ) )
"
"This ends the short script file trip.
"To see all computed expressions click the
"Past Expressions button.
"For more functions look into the Manual or the menus.
"Enjoy.

Você também pode gostar