Calculus0 10

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

Page 1 of 15

Instructions for the Symbolic Calculator


Return to Contents
The yellow field at the bottom of the page is a command line. After you type a command, press Enter to execute it. To re-execute a command, put the caret at the end of the command and press enter. The pink field just above it is a script window. Use this to define commands, programs or execute whole scripts. Type the command or program definition or script in the window, and then press the

button, and the definition is made. Use this for long commands or more complex statements. First, let's do some simple numeric calculations. You should check the Reading mode for numbers before you do this. You can check or set the reading mode by right-clicking on any Command Line, TextBox or on any MathEdit. Right-click the Yellow Command Line to get its menu. Choose: Settings, Read Numbers As... Presently, it says Decimal. Uncheck that and close the box. Now, since nothing is checked, the reading mode is Long, that is, our arithmetic will be with Java integers for now.

Some Arithmetic:
There are 4 basic reading modes for numbers: 1) Long 2) Decimal 3) Big 4) Exact And you can form various combinations of these, such as BigLong, BigDecimal, and so on. Decimal reading mode is most like what you find in ordinary calculators . Long reading mode is primarily for work with whole numbers, but it also works just fine with graphs. Exact reading mode is for work with exact rational numbers (fractions). We will start with Long mode in this demonstration, but we'll need other settings shortly. The reading mode affects the way that MathScript interprets all numbers, even those entered in dialog boxes! The settings can also be made by command in a script or command line. We supplied the readlong command as the first command below. Go ahead and execute it, it won't hurt anything. Place

file://D:\Sites\Mathwright\librarya\galileo\galileo11.htm

2/22/2004

Page 2 of 15

the caret at the end of the line and press Enter. Readlong; (Enter) If you check the mode as before, you will see that it is still Long (nothing is checked). And if you check the precision just below it, you will see that it is 7. You can leave it there since precision does not affect integer calculations. But notice the following: To calculate a number, such as sqrt(10), precede with the word Calc, (case does not matter) so for example, type: calc sqrt(10); (enter) you see: 3.1622776 If the precision were set to 4, you would see: 3.1622 So some decimal calculations work fine in Long mode. The system understands that functions like sqrt, sin, tan, etc. should return decimal numbers. And if you multiply or add an integer to a decimal number, the result will be decimal. But be careful. If you try to get the cube root of 10 by typing: calc 10^(1/3); (enter) you will see: 1 in Long mode. Why? Because 1/3 is translated to 0 first, then the calculation 10^0 = 1 is done! You should do it in decimal mode, but if you really want to do it in Long mode, you would have to type something arcane like: calc 10^(double(1)/double(3)); (enter) And you see: 2.1544346 You may set the decimal precision (say, to 7) with the command: precision 7; (enter) There are many commands in Mathscript. These are a few to try: Now type (and press Enter) calc 2^300; 2037035976334486086268445688409378161051468393665936250636140449354381299763336706183397376 calc 2^300/2^299; 2

file://D:\Sites\Mathwright\librarya\galileo\galileo11.htm

2/22/2004

Page 3 of 15

MathScript did both exponentiations and then did the division. Now try: calc (2/3)^2; The answer 0 is reported. Again, this is because in long reading mode, 2/3 is projected to the integer 0. But try calcexact (2/3)^5; The correct answer: is reported now.

The calcexact command always does the operations in Exact reading mode, and it further simplifies (normalizes) its answer, so that for example, fractions are always reduced. Try calcexact 1/2 + 1/3 + 1/4;

Now, what if we wanted a big number, say 2^1000 calc 2^1000;

107150860718626732094842504906000181056140481170553360744375038837035105112493612249319837881 This is not a Java Integer! It is a Java BigInteger! MathScript automatically translates an exponentiation: long^long to the BigLong type. How about decimal calculations? These are controlled by the Precision setting in the TextBox menu, or by the precision command. We will approximate Euler's number. We want to raise 1.005 to the 200th power. For this, set the Reading mode to Decimal and Big Numbers. Set the Precision to 0. Ironically, this gives "unlimited" precision in a BigDecimal calculation. When you raise a BigDecimal number to a Long Power, you get a BigDecimal. So we have to "force" the exponent to be a Long (and not a BigDecimal) number. The long() function does that for us. Try: calc 1.005^long(200);

2.71151712292937479854899397016290412652651892864411079520031671964003264340274456721329365784

Some Algebra:

file://D:\Sites\Mathwright\librarya\galileo\galileo11.htm

2/22/2004

Page 4 of 15

We will do a few algebraic calculations. For symbolic algebra, it is good to be in Exact Reading mode. We could do this from the menu, but let's use a command. Type: (then press Enter, of course.) readexact; If you check the menu, you'll see that it has been done. Now, let's do a simple calculation: calc (x+1/2)^2;

You see that no expansion was done. The 1/2 was read as a fraction, but the multiplication was not done. But try: calcexact (x+1/2)^2;

calcexact (x+y/2)^10;

Or the trinomial theorem: calcexact (x+y+z)^10; (Mathscript writes the result in prettier form than the following)

x^10+10*x^9*y+45*x^8*y^2+120*x^7*y^3+210*x^6*y^4+252*x^5*y^5+210*x^4*y^6+120*x^3*y^7+45*x^2*y Let's try some other algebraic operations: factor 144; 2^4*3^2 OK, how about a tougher one: factor 2^(2^5)+1; 641*6700417 Now we can also factor polynomials in a single variable. Try: factor y^10+y^5+1;

file://D:\Sites\Mathwright\librarya\galileo\galileo11.htm

2/22/2004

Page 5 of 15

(y^2+y+1)*(y^8+y^3-1*y^7+y^5+1-1*y^4-1*y) Let's check that. You may copy the result and paste it into the command line: calcexact (y^2+y+1)*(y^8+y^3-1*y^7+y^5+1-1*y^4-1*y); y^10+y^5+1

Some Graphing
We can easily graph the built-in functions, like sine, cosine, etc. graph sin; graph cos; graph sin+cos; draw the graph of sin+2*cos using color red, width 2; graph sin#cos color color(0,0,128), width 1; (The # means composition, and we have the choice of 16,000,000 RGB colors with the color(R,G,B) function. Each of the three arguments varies from 0 to 255.) It is also easy to clear the screen. clear; If there was more than one window, we would say: clear in "Graph2D"; to clear the Graph2D named "Graph2D". We might also have used the Actions, Clear Screen menu. Let us define a few new functions and look at their graphs. f(x) := (x+1)^2; To see that the system knows the name "f" of this new function, right-click on the background and select from the menu: Objects, Lexicon, functions... Scroll down the bottom to the User-defined functions, where you see F, and click on it. The system shows: Definition: F(X) is (X+1)^2

file://D:\Sites\Mathwright\librarya\galileo\galileo11.htm

2/22/2004

Page 6 of 15

All mathematical objects are stored in the Lexicon and may be checked in this fashion. graph f width 2 color red; We may ask for a numeric approximation for the solution of an equation using f. For this, we use the roots() function. Here, the first argument is the equation (the variable must always be x), the second is the refinement for the initial partition of the interval, and the third is the interval to search for roots. It is entered as a MathScript vector, and so uses square brackets. Suppose we wanted an approximate solution to

calc roots(f(x)+x=3, 50, [-5,5]); A vector of two approximate solutions is reported: [-3.561552812808803, 0.5615528128088066] Now let's experiment with graphing compositions of functions. clear in "graph"; (Here's another way to define a function.) make g(x) 1/(1-x); h(x) := 1-1/x; graph g color green; graph g#g; (It didn't do a good job with the singularity, but we'll come back to that in a moment..) graph h color red; graph h#h; graph h#h#h; This may be a surprise. It is essentially the identity function. make u h(h(h(x))); calc u; Now, you'll notice that the built-in graph command did not handle the singularity well. You may fix this by executing :

file://D:\Sites\Mathwright\librarya\galileo\galileo11.htm

2/22/2004

Page 7 of 15

curveconnected false; Now all graphs and curves will be drawn without connecting points. Try graph g#g using refinement 1000; To restore the default state, enter: curveconnected true; This may be a good time to discuss user-defined commands. Let us define an interactive command that draws stars. For that we use the Command Protocol. Execute the following command definition in the pink Script Window. Other commands may have output their results to the window, so remove all trailing Ts, NILs and so on from the script below. You execute the script (thus, define the new command) by pressing the at the top of the page.

The command is called Stars. If you right-click on the background and select from the menu: Objects, Lexicon, commands... Scroll down the bottom to the User-defined commands, where you see STARS, and click on it. The definition is: command stars (ex num) [color ex col fillcolor col] { let v be getpoints(true,num); plot polygon v; } This command takes one mandatory argument: the number of points. It also may take one optional argument: the fillcolor. This may be supplied or not, and in any order or placement. But if it is supplied, the fillcolor must be preceded immediately by the word "color". Try it out on the yellow command line: clear; stars 5 using color lred; The word "using" is optional also. After you press Enter, you are expected to click 5 times on the graph2D to make a star! You will see a pointing finger when you move the cursor over the graph2D and when you are finished, you will see something like:

file://D:\Sites\Mathwright\librarya\galileo\galileo11.htm

2/22/2004

Page 8 of 15

Some Calculus:
Next, let's create a curve, a vector-valued function of a single variable. We'll define an ellipse as a function of a single variable t. The use of square brackets in the definition tells Mathscript that the values that this function takes are vectors. First, change the reading mode to Decimal, Precision 7. Type: Readfloat; Precision 7; c(t) := [5*cos(t), 3*sin(t)]; To draw the image of this as t varies from 0 to curve c; or, more informally, Draw the curve c; will cause the curve to be drawn. Next, define a map , use the Curve command.

that takes

file://D:\Sites\Mathwright\librarya\galileo\galileo11.htm

2/22/2004

Page 9 of 15

Type: tr(x,y) := [ x^2 - y^2 + x , 2*x*y -y ]; Next shrink the curve c cc(t) := c(t)/3; curve cc; The image of cc is the image of c scalar-multiplied by . Now, draw the curve which is the composition of tr with cc. curve tr#cc; Next we look at the partial differentiation operator. For this, return to Exact reading mode: readexact; select "mathedit"; calcexact (x+y/2)^5; you see: Now, d(expr, var1, var2, ...) is the partial differentiation operator. Follow the expression with the desired differentiation variables. If you supply no variables, you have the 0th order operator, which is the identity. This has the handy property of normalizing expressions to make it possible to compare them. Thus, in a script, the return value of d(x^2 - y^2 -(x+y)*(x-y)) is the same as the value printed by calcexact x^2 - y^2 -(x+y)*(x-y); That is, 0. Since calcexact does not actually return a value (but prints one as a side-effect) the 0th order differentiation operator is very useful in scripts. calcexact d((x+y/2)^5,x);

file://D:\Sites\Mathwright\librarya\galileo\galileo11.htm

2/22/2004

Page 10 of 15

calcexact d((x+y/2)^5,y);

calcexact d((x+y/2)^5,x,y);

The numeric integration function is integrate( expression in x, refinement, interval). calc integrate(x^3,10,[1,2]); 3.757500000000004 calc integrate(x^3,20,[1,2]); 3.7518750000000036

Some Matrix calculations


This WorkBook has an 8x8 matrix called m defined for it. It is a rational matrix, and so we get into exact reading mode to operate on it. With matrices, we use calc and not calcexact. Just follow along below. readexact; calc m;

make n m^2; calc n;

file://D:\Sites\Mathwright\librarya\galileo\galileo11.htm

2/22/2004

Page 11 of 15

calc n*inv(m);

calc inv(m);

calc m*inv(m);

file://D:\Sites\Mathwright\librarya\galileo\galileo11.htm

2/22/2004

Page 12 of 15

calc transpose(m);

calc det(m); 125411328000 calc det(inv(m));

readlong; Now select, say the upper 4x4 submatrix of m. Select Actions, Copy.

Place the caret at the bottom line of "mathedit" and select Actions, Paste. You may assign that matrix a name in the following way: make u getmatrix(false); Getmatrix(n) returns the nth matrix in the window. Getmatrix(false) simply returns the last one. Thus u is the 4x4 matrix you just selected. Type: calc u^2;

file://D:\Sites\Mathwright\librarya\galileo\galileo11.htm

2/22/2004

Page 13 of 15

calc det(u); 12 calc det(u^2); 144 And so on... You may also create matrices from the command line or from scripts. readexact; make mymatrix zmatrix(2,3); calc mymatrix; Now, modify the matrix by changing a few entries to nonzero values. Just click on an entry to highlight it, and then type in a new number. Type a fraction as say 2/3. To change your mind, navigate with the arrow keys. It takes a little getting used to, but is very intuitive. Put only numeric entries in the matrix (fractions, whole numbers, or decimals). When you are finished, type.

make mynewmatrix getmatrix(false); This assigns the name mynewmatrix to the modified matrix. calc mynewmatrix;

Now create a row matrix. make myrow zmatrix(1,2); make myrow(1,1) 2;

file://D:\Sites\Mathwright\librarya\galileo\galileo11.htm

2/22/2004

Page 14 of 15

make myrow(1,2) 3; calc myrow;

Let's try some formatted output.


output "/v * /v = /v", myrow, mynewmatrix, myrow* mynewmatrix;

Just a little sprite animation


First, create two sprites for the "Canvas" Graph2D. The command is: sprite <spritename> <path to bitmap> <initial position>; sprite "red" "b6.bmp" [2,0]; sprite "blu" "b3.bmp" [-2,0]; Now, let's move them around. For that we create a curve, a circle of radius 2. make c(t) 2*[cos(t), sin(t)]; curve c; Set decimal mode. readfloat; Now type or paste the following program in the pink script window (after you have erased the one that is there). do i=0 until i>6.3 { movesprite "red" to c(i); movesprite "blu" to c(pi-i) ;

file://D:\Sites\Mathwright\librarya\galileo\galileo11.htm

2/22/2004

Page 15 of 15

i := i+pi/20; } Press the and watch them go!

There are over 270 built-in commands and functions in Mathscript. You can see them listed in the Lexicon from the menu: Objects, Lexicon. In your browser, you get this menu by right-clicking on the background.

file://D:\Sites\Mathwright\librarya\galileo\galileo11.htm

2/22/2004

You might also like