KAlgebra/Console Tab: Difference between revisions
(A brief tutorial on the KAlgebra Console) |
|||
Line 23: | Line 23: | ||
What I did here is define (:=) the function AreaRect. AreaRect is a function of two free variables b and h (base and height). The lambda operator (->) shows how they are mapped into the area of a rectangle. After you key this function in, the AreaRect function is built into KAlgebra. Go ahead, type in, AreaRect(4,2), you will get the answer, 8. | What I did here is define (:=) the function AreaRect. AreaRect is a function of two free variables b and h (base and height). The lambda operator (->) shows how they are mapped into the area of a rectangle. After you key this function in, the AreaRect function is built into KAlgebra. Go ahead, type in, AreaRect(4,2), you will get the answer, 8. | ||
Below is a screen shot showing how this most basic of functions is defined, displayed in the variable list, utilized by the user, with results shown in the display. | |||
== Help! (or is it Help?) == | == Help! (or is it Help?) == |
Revision as of 01:23, 1 December 2011
Getting to Know the Console
The KAlgebra console tab is the first thing you see when you open the KAlgebra program. It is like a calculator, but way better. The small edit field at the very bottom of the screen is the input bar. It is used to input the the problem that you want to solve. The answer is shown in the display area in the middle of the screen. On the right, there is a medium sized window which is the variable window. This shows the current values of the variables, such as: pi, true, false, and even the current answer. The console can be used to make simple and complex calculations, and it's easier and quicker than bringing up a calculator function. In order to do calculations, you enter the equation you want to be solved into the input bar. After you press enter it will show you the answer in the display area.
Equals!! or Equals? that is the Question
One of the main things you must know about KAlgebra is the difference between equals! and equals? I know what you're thinking, “What's the difference?”. Well, equals. (:=) is used to set or define the value of the variable you have chosen. For example, y:=3 defines y as equal to 3. Equals? (=) means you are inquiring as to whether or not a variable is equal to that value. You will receive either the answer true or the answer false in this case. For example, if you input y:= 3, then enter y=2, your answer you will get will be “false”. So, := is the operator that KAlgebra uses to define, and = is the logical operator (that goes along with < > <= and >=).
KAlgebra as a Kwicker Kalculator
There are also basic calculator functions such as, addition (+), subtraction (-), multiplication (*), division (/), exponents (**) and(^), and order of operations()[Please Excuse My Dear Aunt Sally ;-)]. If you want to take the square root of a number,you type the number followed by ^0.5. For example, the square root of five: 25^0.5. When using a calculator program on the computer you must mouse around the different virtual key. KAlgebra's console allows you to just type in what you want to solve which is much faster and more direct.
Setting up User Functions with the Lambda Operator
The lambda operator is difficult to wrap your head around at first glance. Basically, it is the way to define a new function in the KAlgebra console. The best way to discuss how to use it is by example. An example of what the area of a rectangle would look like would be:
AreaRect:=(b,h)->b*h
What I did here is define (:=) the function AreaRect. AreaRect is a function of two free variables b and h (base and height). The lambda operator (->) shows how they are mapped into the area of a rectangle. After you key this function in, the AreaRect function is built into KAlgebra. Go ahead, type in, AreaRect(4,2), you will get the answer, 8.
Below is a screen shot showing how this most basic of functions is defined, displayed in the variable list, utilized by the user, with results shown in the display.
Help! (or is it Help?)
The dictionary is the best source for all of KAlgebra's available functions. You just click the dictionary tab, and you will get a list of all 64 functions. If you want to edit the value of a variable, you can double click on the current value in the variables list and enter anything you want. KAlgebra includes an auto complete feature which will suggest possible functions you may use for your calculations. It starts working when you begin typing in the input bar. Once you type in at least one letter, it will give you several options as to what you may want to enter. If one of those options is suitable, you click on it, and what you've been typing will be automatically completed.
The Ultimate Example of Math Geekery
To show some of the KAlgebra console concepts, we would like to find the area under a sine curve. To do so, we are going to estimate the area as the area of a bunch of trapezoids that fit under the sine curve. For starters, we define a function (f) that provides our sine curve from 0 to 3.14 radians:
f:=x->sin(x)
We didn't have to do this, we could just use sin(x) directly, but we can also replace sin(x) in the definition of f to find the area of other interesting shapes.
Next we define a function that is able to calculate the area of a trapezoid:
A:=(b,h1,h2)->0.5*(h1+h2)*b
The above function is a function of three variables (base, height 1, and height 2) that KAlgebra is more than capable of handling.
Next, we are going to evaluate the series of trapezoids beneath the sine curve in increments of 0.01 radians. To help us do this, we define a helper function x(k)=0.01*k or:
x:=k->0.01*k
So that as k counts from 0 to 314, x changes from 0 to 3.14 radians. We sum the trapezoid areas up using sum function:
sum(A(.01,f(x(k)),f(x(k+1))): k=0..314)
This shows off a lot of KAlgebra's capabilities and syntax. You can see the use of the built in function, sum. We show off the use of nested functions. Also, we see the use of the range syntax.
Our answer is very close to two, which happens to be the exact solution.
--trLanzi 01:10, 1 December 2011 (UTC)