/* [wxMaxima batch file version 1] [ DO NOT EDIT BY HAND! ]*/ /* [ Created with wxMaxima version 19.05.7 ] */ /* [wxMaxima: title start ] Symbolic mathematics Exercise package A [wxMaxima: title end ] */ /* [wxMaxima: comment start ] Author: X E-mail: x.x@x.x [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Instructions: Replace above X with your name and insert your email below. Edit name of the file by replacing the X with your last name. [wxMaxima: comment end ] */ /* [wxMaxima: section start ] Basic Syntax [wxMaxima: section end ] */ /* [wxMaxima: subsect start ] Input and comment cells, running cells [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Compute 3+4, 5*9 and 4^2. These are already written below; choose cells one at a time and run cells by pressing shift+enter. (Pressing only enter will merely add a row change to the cell.) [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ 3+4; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ 5*9; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ 4^2; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] There is two options for raising numbers to powers: ^ and **. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Compute below, what is (1+5)*2. First, click between cells so that the cursor is flashing horizontally. Then you are able to write your commands. wxMaxima adds semincolons automatically, but you may add them manually as well. Also, you may try command "Insert input cell (ctrl+0)" available in menu (Cell). [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Computation (1+5)*2 should be above this comment. Create a new text cell below this cell. You may use right click or you may find the right command from Cell menu. Write a comment about this exercise to the created text cell. Did you manage on your first try? [wxMaxima: comment end ] */ /* [wxMaxima: subsect start ] Saving [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Save this file. It is recommended to use wxm file extension. Another option is to use wxmx. Difference between wxm and wxmx is that wxmx saves outputs as well as inputs while wxm only saves inputs. Unless otherwise stated all exercises in this course are returned as wxm files. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Comment following questions in a new text cell below. What happens to computations in exercise 1.1, when you save, close and reopen this file? What was stored, what was not? [wxMaxima: comment end ] */ /* [wxMaxima: subsect start ] Symbolic and numerical outputs [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Maxima syntax for the constant pi is %pi. This constant multiplied by two is 2*%pi. What Maxima gives as output, if you compute this? Compute and comment. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] There are a few options for getting a numerical output. Try following commands and comment the outputs: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ float(2*%pi); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ 2*%pi, numer; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ bfloat(2*%pi); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ bfloat(2*%pi), fpprec:10; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ bfloat(2*%pi), fpprec:20; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] It appears that when writing a command, further adjustments can be made by writing them after the command separeted by a comma. The command "numer" changes outputs to numerical form. The value of variable "fpprec" adjusts accuracy of the output. [wxMaxima: comment end ] */ /* [wxMaxima: subsect start ] Variables [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Often it is not practical to carry out long and complicated computations all at once. It is more reasonable to split computation into parts. This is what variables are for. Maxima interprets unassigned variables as real numbers by default. A colon is used for assigning values to variables. The equality sign is reserved for other purposes. Run following cells. Add text cells and comment outputs in between and to the end. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ x+y; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ y:3; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ x+y; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ x:2; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ x+y; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Next, assign the value pi to a variable z and compute x+z numerically. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Name of a variable can be longer than one symbol. To this end it is relevant to always remember to use multiplication sign (*) when computing products. Run following cells. Notice how "xy" does not have a value since it has not been introduced yet. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ x*y; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ xy; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Values of variables can be changed. Assign a new value to variable y and compute x*y again. [wxMaxima: comment end ] */ /* [wxMaxima: subsect start ] Constants [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] As we already saw pi in Maxima is written as %pi. Respectively we get another familiar constant by writing %e. It is important to add the percent sign. Maxima interprets inputs "pi" and "e" as variables, if % is left out. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Compute e^(pi^2) numerically. [wxMaxima: comment end ] */ /* [wxMaxima: subsect start ] Commenting [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] From this point on it is always assumed that you explain your computations with comments. However, not every obvious thing needs a comment. For example, command "x:10" does not need comment "we assign value 10 to variable x". Rather comments should be thought of as the text part of answers to mathematics questions. For example, following chain of comments is advisable: - We assign variable name y to the expression given in this exercise. We name its derivative as yd. - We solve roots of the derivative and collect them into variables x1, x2, etc. - We substitute to expression y the roots of the derivative, that are in correct interval, and the end points of this interval. - Thus maximum of the function is... - ...and minimum is If there are commands in between comments like this, it makes the code easier to follow. Answers to exercises should always be given as text. Of course calculation is enough, if the answer is only an output of a computation. However often this is not the case. As a rule of thumb, exercise is not done unless its commented. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] What are 5^6 and 6^5 equal to? Which number is greater? [wxMaxima: comment end ] */ /* [wxMaxima: section start ] Manipulation of expressions and functions [wxMaxima: section end ] */ /* [wxMaxima: subsect start ] Expressions [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] A variable can depend on other variables. A common name for variables of this type is expression. The simplest expressions only contain a number or a variable, but expressions can be more complicated than that. Next, we create an expression called "expression", that depends on two variables. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ expression:variable-number; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Let's try computing with this expression: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ expression+number; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ expression^2; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Maxima does not simplify expressions unless we command it to. It depends on the situation, what is the most simplified output. We return to simplification later. [wxMaxima: comment end ] */ /* [wxMaxima: subsect start ] Substitution [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Variables of an expression can further depend on other variables. We may ask the value of an expression or a variable from Maxima by giving its name as an input (categorically expression and variables are equivalent in Maxima). Next, we ask the value of an variable before and after redefining it. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ expression; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ number:anotherNumber+3; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ expression; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Maxima does not substitute its knowledge about the variable "number" unless it is told to. Command ev ("evaluate") forces substitution. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ ev(expression); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Even more important is the option to assign a value to a variable for the duration of an evaluation. Next we create a new expression and compute its value at h=2: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ square:h^2; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ ev(square,h=2); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Notice that when substituting into variable the value is given with equality sign =, not with a colon :. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Using the command ev means evaluation with further adjustments. In practice (in simple situations) substituting a value to a variable produces the same effect. The output above can also be computated as in: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ subst(h=2,square); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Ask values of square and h from Maxima. What do you notice? [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] You may also substitute more than one value at a time. Computing the area of a triangle works as follows: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ area:a*b/2; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ ev(area,a=2,b=3); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ subst([a=2,b=3],area); /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] Familiar functions [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Many familiar functions are predefined in Maxima: sin, cos, tan, log, exp... Inverse functions of trigonometric functions are asin, acos, atan... Ordinary brackets () are always used when operating with functions. For example arccosine at zero is: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ acos(0); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Calculate cosine of the output. Did you get a zero? [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Name the function sin(x) and compute its value at x equal to pi. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Commands subst and ev introduced above are also functions. It isn't fundamental for a function to produce output numbers from input numbers. Function can perform a lot of other things as well. And this is the case in mathematics too! [wxMaxima: comment end ] */ /* [wxMaxima: subsect start ] New functions [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] You can create new functions in Maxima and use them as you might use predefined functions. Let us define a new function: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ f(z):=z^3-5; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Notice, how we used := and not just : or =. Computing the value of a function at a point happens as follows: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ f(3); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Define a function g(z) = 4z+9 and an expression gexpression=4x+9. Remember to use multiplication sign. Compute the value of g at z=-1 in two ways by using the function and by using the expression. Did you get same outputs? Which option would you prefer? [wxMaxima: comment end ] */ /* [wxMaxima: subsect start ] Simplification [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] There are basic commands expand and factor for simplifying polynomials. Try following commands and describe in words what they do. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ expand(z*(1-z)+3*(z^2-2*z)); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ factor(z^2-4); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] There is a separate item for simplification in the menu bar of wxMaxima. Create expression tan(p)+tan(q) ------------- tan(p)-tan(q) and try what different trigonometric simplification commands produce when applied to it. What is the simplest form in your opinion? [wxMaxima: comment end ] */ /* [wxMaxima: subsect start ] Killing objects [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Let's try simplification from previous exercise with a different variable: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ factor(x^2-4); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] You get this strange output, since x is not a free variable. It has been assigned a value before. Ask Maxima for the value of x. Does the output of above factor command make sense now? [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] We may unassign the value of x by killing the variable: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ kill(x); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Now, ask Maxima for the value of x again and try the factor command above again. Does it function as expected now? [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Sometimes it's useful to kill all functions, variables, lists and others defined before and to start over. This can be done with dramatical command: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ kill(all); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Now, try what Maxima says about f(x), y and sin(pi). What do you notice? [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] From this point on it's good practice to start all exercises with kill(all) unless an exercise continues previous one. [wxMaxima: comment end ] */ /* [wxMaxima: section start ] Recap [wxMaxima: section end ] */ /* [wxMaxima: comment start ] Compute the sum and the product of 1/8 and 3/5. Name them and then compute the third power of the difference of the sum and the product. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Open Maxima's help menu and choose index from the top of the page. Find sections about ":" and "numer" from where you can see more information about variables and numerical evaluation. Were you able to find them? Mention something about ":" and "numer" that wasn't covered in this file. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Create expression sin(x)^2+cos(x)^2 and name it "one". Try different simplification functions. Can you produce a familiar output for the expression? [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Now, create a similar expression, but change one of the powers to something other than two. How does this expression simplify? What is the value of your expression when x is equal to half of pi. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Last task: Save the file (wxm file extension, not wxmx), close the file and reopen it. Select command "Evaluate all cells" from menu. Then maxima runs all input cells in order. When running is complete, go through the whole file and check that all computation were successful and recheck that you answered all question. Is everything in order? [wxMaxima: comment end ] */ /* Old versions of Maxima abort on loading files that end in a comment. */ "Created with wxMaxima 19.05.7"$