Ana səhifə

Maxima Handbook Introduction

Yüklə 28.25 Kb.
ölçüsü28.25 Kb.
Maxima Handbook

Maxima can operate as a calculator
(%i1) 2+3;

(%o1) 5
where (%i1) means the first line of input and (%o1) is the first line of output..

(%i1) 2+3;

(%o1) 5

(%i2) 2*3;

(%o2) 6

(%i3) 2/3;

(%o3) 2/3

Note that 2/3 is a fraction.c You could make if a decimal result if you made either the 2 or the 3 a decimal number

(%i5) 2.0/3;

(%o5) 0.66666666666667
or you could use the float() command
(%i6) float(2/3);

(%o6) 0.66666666666667

You can compute factorials
(%i1) 10!;

(%o1) 3628800

You can raise numbers to powers using the same symbol as in Excel. To raise 2 to the second power

(%i1) 2^2;

(%o1) 4

To raise 2 to the third power

(%i2) 2^3;

(%o2) 8
To raise 3.3 to the one hundredth power

(%i3) (3.3)^100;(%o3) 7.1022178218665199*10^+51

You can use the power command to take square roots

(%i1) (4)^(1/2);

(%o1) 2

and third and forth roots
(%i3) float((4)^(1/3));

(%o3) 1.587401051968199

(%i4) float((4)^(1/4));

(%o4) 1.414213562373095

or go wild and take the 100th root
(%i5) float((4)^(1/100));

(%o5) 1.013959479790029

If you want you can find values of the exponential function
(%i5) exp(10.0);

(%o5) 22026.46579480672

and take the natural logarithm
(%i7) log(22026.46579480672);

(%o7) 10.0

One thing you will need to do is assign values to variables. For example suppose that you want to give x a value of 3.
x : 3

Note the way you do it: x : 3. That is x followed by a colon followed by a 3.

The Maxima output is
(%i1) x:3;

(%o1) 3
where (%i1) means the first line of input and (%o1) is the first line of output.

Suppose we assign x a value of 3 and y a value of 2 and add the two
(%i1) x:3;

(%o1) 3

(%i2) y:2;

(%o2) 2

(%i3) x+y;

(%o3) 5
And perform other operations on these symbols

(%i4) x/y;

(%o4) 3/2

(%i5) float(x/y);

(%o5) 1.5


(%i6) x*y;

(%o6) 6

Solving equations
Maxima can solve equations with two unknowns
(%i1) solve([x+y=3,x-2*y=4],[x,y]);

(%o1) [[x=10/3,y=-1/3]]

or three unknowns
(%i2) solve([x+y+z=2,x-y+z=3,x+y-z=4],[x,y,z]);

(%o2) [[x=7/2,y=-1/2,z=-1]]

Expressions are mathematical statements assigned to labels like eqn1, eqn2, etc.

(%i3) eq1:x+y+z=2;

(%o3) z+y+x=2

(%i7) eq2:x-y+z-3;

(%o7) z-y+x-3

(%i8) eq3:x+y-z=4;

(%o8) -z+y+x=4
Expressions make solving equations a bit more elegant
(%i9) solve([eq1,eq2,eq3],[x,y,z]);

(%o9) [[x=7/2,y=-1/2,z=-1]]

We will make heavy use of functions in this class. A function is defined using the := symbol. Suppose you want define the function f(x)=x+3 in Maxima. The command to use is
Then the value of f(x) at x=10 is
(%i2) f(10);

(%o2) 13
and if x=3.3

(%i3) f(3.3);

(%o3) 6.3

You can define two functions and solve for the value of x that makes them equal
(%i1) f(x):=2*x+3;

(%o1) f(x):=2*x+3

(%i2) g(x):=x/2+4;

(%o2) g(x):=x/2+4

(%i3) solve(f(x)=g(x),x);

(%o3) [x=2/3]

Then you can evaluate the functions to see if the solution is correct
(%i4) f(2/3);

(%o4) 13/3

(%i5) g(2/3);

(%o5) 13/3

and it looks like Maxima was successful.

It will often times be useful to assign the solution to a label. If you want to assign the solution to a label like ans (for answer) type

(%i6) ans:solve(f(x)=g(x),x);

(%o6) [x=2/3]

and now ans contains the solution of the equation. Now we can refer to the label ans
(%i7) ans;

(%o7) [x=2/3]

Unfortunately ans contain the string x=2/3. What we really want is the right hand side (rhs) of the expressions x=2/3. We can get the rhs of the expression using the following command
(%i8) ans:rhs(ans[1]);

(%o8) 2/3

(%i9) ans;

(%o9) 2/3

The rather mysterious command (%i8) ans:rhs(ans[1]); means let ans have the value of the right hand side of the expression in ans. In other words ans has been given a new value equal to the right hand side of the old value of ans. The reason for the ans[1] in the mysterious command is explained in the next section.

This is useful because now we can use ans as a numerical value

(%i10) f(ans);

(%o10) 13/3

(%i11) g(ans);

(%o11) 13/3

More than one solution to an equation
The command ans:rhs(ans[1]) contains the odd seeming ans[1]. That is because equations can have more than one solution. Consider solving x^2-1=0
(%i1) f(x):=x^2-1;

(%o1) f(x):=x^2-1

(%i2) ans:solve(f(x)=0,x);

(%o2) [x=-1,x=1]

Now there are two solutions for x^2-1=0, they are x=-1 and x=1. We can get these two solutions using
(%i3) x1:rhs(ans[1]);

(%o3) -1

(%i4) x2:rhs(ans[2]);

(%o4) 1
and just to see if we are correct, evaluate f(x) using x=1 and x=-1

(%i5) f(x1);

(%o5) 0

(%i6) f(x2);

(%o6) 0

Example 1

Using Maxima to solve supply and demand problems.

Suppose a demand function is defined as
D(p) =100 –p
where quantity demanded will decrease as p increases. The supply function is defined to be S(p) = 2p where quantity supplied increases as p increases. Use Maxima to solve for p.

(%i1) D(p):=100-p;

(%o1) D(p):=100-p

(%i2) S(p):=2*p;

(%o2) S(p):=2*p

(%i3) ans:solve(D(p)=S(p),p);

(%o3) [p=100/3]
Now check to see if these solutions are correct. Note p_eq is where we store the value of the equilibrium price.
(%i4) p_eq:rhs(ans[1]);

(%o4) 100/3

The equilibrium quantity demanded is

(%i5) D(p_eq);

(%o5) 200/3
and the equilibrium supply is
(%i6) S(p_eq);

(%o6) 200/3

Example 2
Example 2 extends example 1 and makes it a bit more general
Let demand be

where p again is price and Y is income. are parameters that specify how demand changes if p or Y change. If p changes by one unit, then D(p) will change by units and if Y changes by one unit D(p) will change by units.

The supply relation is

where C represents the cost of producing a unit of output. Maxima can solve this model

Next we can give values to the parameters and get numerical answers to the model

Note that you can enter more than one statement on a line. If you terminate the statements with a $, the statement is not printed. The ‘rat’ statements are something Maxima puts in.

Next check to see if supply really does equal demand

Supply does equal demand so the solution is correct.
Next suppose that the cost of production increases from C=1 to C=2. This should decrease supply and raise prices.

Price did rise (from p=101/2=60.5 to p=51). The equilibrium output fell from 49.5 to 49.0.

Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur © 2016
rəhbərliyinə müraciət