This workbook contains the wxMaxima commands that appear in 
Sections 1 - 4 of Chapter 1.

The cell below is optional. The purpose of each of the commands
is indicated in the final section of Chapter 1 in the text.

load(draw)$ 
set_draw_defaults(  fill_color=gray40,
draw_realpart=false,font_size=10)$
fpprintprec:5$ ratprint:false$kill(all)$

# Chapter 1. Introduction

Chapter 1 covers the elements of Maxima that pertain to the
development and illustration of economic models in the rest
of the book. This workbook contains the commands that generate
the commands and the resulting output that are reported in 
the book.

Occasionally, we add a command or two, in order to extend or
build upon material in the text.

The cells below show the commands. You may execute all of the
commands in this workbook now but using ctrl-r or by using 
the menu sequence Cell/Evaluate all cells. Alternatively, you
may execute one cell at a time as you work through the material
by clicking on the cell and using ctrl-space or ctrl-enter, or
by using the menu selection Cell/Evaluate cell(s).

## Basics (Text Section 1.1)

First we enter a few commands in wxMaxima, one command per
cell. In each case, the command is assigned a number, %i1
for the first one, and so forth. Likewise, the output is 
reported an assigned a number. Until Maxima's memory is 
cleared (the kill command, which accomplishes this is covered
later), thes names remain and can be recalled.

4*5;

The entire command need not be on the same line. wxMaxima
does not recognize line breaks or spaces. It knows a command
has ended when it encounters the semicolon (or dollar sign,
discussed later).

1 + 2 + 3 + 4 + 5 +
      6 + 7 + 8;

Commands are not limited to values. Names can be entered as 
well.

2*x- 5 + 3.5*x;

Maxima has a range of arithmetic and algebraic operations built
in. Three of the arithmetic operations appear in the preceding
three cells. The next two cells show how to raise a value to a
power.

-2^4;

(-2)^4;

Maxima can calculate factorials.

5!;

Expressions as well as values can be the subject of operations.

(x + 3)^2;

The % operator can be useful. In the cell below, it recalls
the output that was created above and subtracts 5 from it.

Take care with the % operator. It refers to the 
most recent output, not the one in line inside the workbook.
Thus, if you had moved ahead one command cell, executed the
cell, and returned to the cell just below, your results 
would change. 

In general, it's probably a good idea to refrain from using
the % operator except within a cell that contains a set of
commands.

% - 5;

We can recall the output from the execution of a specific
numbered command, as below.

%o7;

We can place a number of commands inside the same cell and
execute them all at the same time. The example below is a
fairly complicated example, in that it contains four 
commands, along with the use of subst( ) to make 
substitutions, and the embedding of one command, subs( ), 
inside another, log( ). For now just observe the results. 

We look at both subst( ) and embedding in more detail as 
the chapter progresses. 

(In the text, all of these are placed in a list. We'll
look at lists below.)

y: (x-1)^2;
 subst(3.0,x,y); log(subst(x=3.0,y)); y+5;

## The wxMaxima Screen (Text Section 1.2)

This wxMaxima screen consists of five parts.  
First, the title bar identifies the 
file being used, if a session has been saved as a named file. 
Next, a series of menus provide a relatively easy way of 
implementing most of \emph{Maxima}’s important commands.

By the way, another menu is available, one that you might
prefer for some purposes. Select Maxima/Panes/General Math.
The result is a set of buttons that automate a good bit of 
your interactions with wxMaxima. If you prefer this way of
working, you might also turn on the Insert Cell pane. You 
can move these panes anywhere on your screen, inside or 
outside of the workbook.

The third row in the screen contains some commonly-used 
icons. The list below is consistent with version 12.04. As 
wxMaxima development has progressed, more icons have been
added, and this might continue.

The first opens a new wxMaxima session, and the 
second one opens a session that has been previously created 
and saved. Be aware that selecting this one prepares wxMaxima
to replace the current session with a previously saved one.
It prompts you with a dialog box asking whether you want to
save the content of this session before proceeding. If you a
actually want to keep this on open and to open a existing 
session, click on the first icon to create a separate 
session window and then click on the second icon to open your
existing workbook.

The next icon saves the current session. The third icon prints
the current session, showing both input and output. The 
default is to print the contents of the workbook to your
designated printer. An option to print to a file (PDF) is 
available in the print dialog box.

The fifth icon allows for configuring wxMaxima workbooks. 
The next two icons copy or cut a selection. The eighth icon 
pastes material from the clipboard. This option can be 
somewhat problematic in that extranenous hard returns might
be included. These might not be apparent until you've saved 
and reopened the workbook.

The ninth icon opens a "find and replace" dialog box. 
The tenth icon interrupts the execution of a command The 
next three icons control animation (not addressed in the 
text but are demonstrated below. The last one opens The 
Maxima Manual.

The fourth part of the screen is a window that contains input and 
output. That is, it's what you're looking at now.
The fifth part is the status line below.

## Mathematical Functions (Text Section 1.3)

The cell below contains a list of commands. The result of
executing ths list is an output list. These lists show \
how to execute a few of Maxima's many internal commands
and the resulting output.

Most of the material here requires little attention, but 
two aspects merit note. First, log( ) relates to the natural
log, not to the command (base 10) log. Second the value %i
is Maxima's way of designating sqrt(-1).

a: -44$  [abs(a), sqrt(a), float(exp(a)),log(a)];

By the way, if you want a base-10 log, you can create one,
as follows: devide the natural log of a value (100 here) by
the natrual log of 10. We had to do this twice, because the
first pass seems to simply repeat the command. Actually, 

Maxima has computed the value, but it reports its exact 
value, which is not very informative. One way to force 
Maxima to report a numerical value is to enter both 100 and 
10 as floating-point values. We discover, properly, that the
base-10 log(100) equals 2.

log(100)/log(10);
log(100.0)/log(10.0);

Maxima has a full complement of trigonometric functions. We 
mention these mostly for completeness here. The text does not
use trig.

%theta : %pi/3$  [x1,x2,x3]:[sin(%theta), cos(%theta),tan(%theta)];

The inverse trig functions are also available.

[asin(x1),  acos(x2),  atan(x3) ];

Functions can be embedded within each other. 

[y:log(exp(2)), sin(%pi/2), y+sin(%pi/2 )];

The % operator should be used inside a cell. 
Strange results can occur. Execute the command below.

What result did you expect to find as a result of the
third command? (w1 and w2 are randomly selected names,
and have no special meaning.)

[w1+1, w2+2, %^2];

Confirm your intuition by executing the input group
below.

[w1+1, w2+2, (w2+2)^2];

As noted in the text and above, Maxima reports exact 
values unless forced to report floating-point representations.

We saw one way to force this sort of representation above.
A second way is to embed the command inside float( ).

[atan(%pi/2),    float(atan(%pi/2))];

The book notes that gibberish and actual output can look 
the same. Execute the cell below. The first cell ln(50) is
gibberish; Maxima does not know what ln( ) means, so it 
returns the command. The second command, likewise, is 
gibberish, as far as Maxima knows. It states that the 
answer to ln(50.0), whatever ln( ) might mean, is ln(50.0),
but it makes no attempt to evalate that expression.

In contrast, the third piece of output, log(50) is an 
exact result of the proper command log(50). The forth 
output line shows a floating-point represnetation of that
value.

ln(50); float(%); log(50); float(%);

## Referring to and Evaluating Expressions
(Text Section 1.4)

The first command below kill(all) removes all named values
from Maxima's memory. If you execute it and then try to recall
any of the names that were assigned in earlier sections, 
including output names like %o10, you will fail. That 
information will been deleted.

The kill(all) command ends with a dollar sign. Ending it with a
semicolon would result in a statement, "done"--try it.
The first list contains three commands. The first command
assigns (or binds, using The Maxima Manual's favored 
terminology) the name x to the expression 3*5 - 1/2. 
The next two commands carry out operations on x, which is 
to say on the expression bound to x.

The next list contains a command that binds the name u
to an expression that involves a numerical value and the
value w, whose numerical value we do not know. It also 
contains a command to square u, and then a command that
instruct Maxima to report the names of values that it 
retains in its memory at this point.

Note, by the way, the output numbers. Executing each 
list of commands is treated as a single command, so that
the result is a named list.

kill(all)$ [x : 3*5 - 1/2,  x^2,  1.0*x^2];
[u: 4 + w, u^2, values];

Recalling the output %o2 confirms that the result is a list.

%o2;

The kill( ) command can be used selectively.

kill(x)$  y : 1 + w^2;   values;

TeX: When moving from one problem to another, it is best to clear 
previously assigned variables. Suppose that we define  
w=3+5*x but forget that x has been bound to the value 29/2. 

The variable $w$ evaluates to 151/2, rather than being an 
expression stated in terms of the value of x.

Note that the cell below differs from its counterpart in the
text in that the commands are not in a list and in that 
the results of the first and third commands are not printed.

x:29/2$   w:3+5*x;   kill(x)$   w:3+5*x;

### Bindings and Functional Expressions

Maxima provides three ways to relate an expression to a 
name: temporary bindings (or assignments), permanent bindings,
and functional expressions.

Temporary bindings, established with =, are often used  to 
evaluate an expression under a specific set of conditions. 

In the example below, x is bound temporarily to the value 1
and then to the value %e (approximately 2.718, another value, 
like %, that is stored permanently in Maxim's memory), 
and finally to a value slightly larger than %e. 

In each case, y is evaluated given the temporarily assigned 
x value, using the ev( ) command.

kill(all)$ y:log(x)$ [ev(y,x=1),ev(y,x=%e), ev(y,x=2.8)];

TeX:
\emph{Maxima} can specify functional relationships in 
a way that allows direct entry of the function's
arguments. The name y is bound  to variable $x$. 

Then a function of x, f(x), is defined.  

kill(all)$    [y:5+x,  f(x) := 5+x];

The next cell evaluates y and f(x) when x = 3. It does so
in four different ways:
1. Append the temporary assignment x = 3 to the expression
   that is named y.
2. Enter the temporary assignment x = 3 in the ev( ) 
   command, where the arguments are the expression and 
   the temporary assignment.
3. Use subst(3,x,y), which substitutes 3 for x in y.
4. Use subst(x=3,y), which evaluates y given that x = 3.
   We usually use this option, which is easily generalized
   to allow a list of expressions.
5. Use the functional expression f(3), which instructs 
   Maxima to evaluate f(x) when x = 3. 

y, x=3;  [ev(y,x=3),subst(3,x,y),subst(x=3,y), f(3)];