/* [wxMaxima batch file version 1] [ DO NOT EDIT BY HAND! ]*/ /* [ Created with wxMaxima version 17.10.0 ] */ /* [wxMaxima: title start ] Symbolic Computing Exercise package C [wxMaxima: title end ] */ /* [wxMaxima: comment start ] Author: X E-mail: x.x@x.x [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Instructions: Fill in your name and e-mail as before. Rename the file as with previous packages. When answering questions remember to comment your calculations. Commenting improves readability and is in fact one of the evaluation criteria. Some formulas have been written on a separate file for clarity. See the course page for this file. All problems are mandatory. If an exercise feels insurmountable, write a comment saying so and compensate for that by an additional problem from package X. Do ask for help if anything confuses you! [wxMaxima: comment end ] */ /* [wxMaxima: section start ] Special Functions [wxMaxima: section end ] */ /* [wxMaxima: input start ] */ kill(all); /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] map and apply [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Consider the list [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ lst:[[1,-8.3], [2,-8.5], [3,-3.8], [4,2.2], [5,8.9], [6,13.7], [7,16.5], [8,14.1], [9,8.8], [10,3.6], [11,-2.0], [12,-6.2]]; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] This list represents monthly averages of temperatures. Let us compute the yearly sum of temperatures. We showcase new functions map and apply. Try what following commands do: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ map(f,[a,b,c]); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ apply(f,[a,b,c]); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Maxima has a strange function "+". This can be used to compute a sum of as many numbers as one likes: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ "+"(a,b); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ "+"(12,43,71); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Try the commands "=" and "-". [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] We see that sum of elements in a list [a,b,c] can be computed as: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ apply("+",[a,b,c]); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Define a function [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ SUM(list):=apply("+",list); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] That is SUM computes the sum of elements in the argument list. To compute the sum of temperatures we need to collect temperatures in a new list. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Define a function f to help collecting temperatures. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ f(list):=list[2]; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Applying map to f and lst, we get a list of temperatures. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ temperatures:map(f,lst); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Thus the sum is [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ SUM(temperatures); /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] part [wxMaxima: subsect end ] */ /* [wxMaxima: input start ] */ kill(all); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] The function part used to extract a part from an expression. The way to think about this is that an expression in Maxima is formed from shorter parts. A simple expression x^5 is formed from only three parts: x, ^ and 5. These are given an order as follows: Part number 1: x Part number 2: 5 Part number 0: ^ Number 0 corresponds to the outernmost part (x^5 is formed from x and 5 by adding ^ between). After the outernmost part other parts are numbered in order. To illustrate the zeroth part see what following commands do: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ part(sin(x),0); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ part(f(x,y),0); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] To complete the example explained above try following commands: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ part(x^5,1); part(x^5,2); part(x^5,0); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] To be completely honest all operations, such as + and ^ are functions. For example, Maxima has functions "+" and "^" that work as follows: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ "+"(2,3); "^"(2,3); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] For comparison [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ 2+3; 2^3; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] A more complicated expression splits into shorter expressions in a "tree like" manner. Let's see how part-function works with expression x^5 + sin(x) + 7: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ expr:x^(y+2)+sin(z)-7; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ part(expr,1); part(expr,2); part(expr,3); part(expr,0); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Now that the expression is split into parts, these parts can further be split into shorter parts: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ part(expr,2,1); part(expr,2,2); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ part(expr,2,2,1); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] The part-function can be used to extract elements from a list: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ part([1,4,9,16,25],4); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] This gives the same output as the usual [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ [1,4,9,16,25][4]; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] As last example, let's plot a polynomial and its root to a same picture. We used part and makelist to collect a solution set from output of a solve command to a list: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ poly : x^3 + x^2 - 3*x + 1; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ roots:solve(poly); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ rootlist: makelist(part(roots,i,2),i,1,length(roots)); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] The rootlist contains only x-coordinates of solutions and thus we give y-coordinates of solutions in a list ([0,0,0,]). [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxplot2d( [poly,[discrete,rootlist,[0,0,0]]], [x,-5,5], [y,-5,5], [style,lines,points], [point_type,asterisk] ); /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] Exercises [wxMaxima: subsect end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] Consider the following expression: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ expr:x^(y+2)+sin(z)-7; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Explain what following command gives. Does it match your expectation? [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ part(expr,2,0); /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] Define a function AVG that takes a list object as an argument and computes the average of its as an output. Use the SUM defined in 3.2 and lenght function. How do you compute the yearly average of temperatures using AVG? [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] In the previous exercise we computed the yearly average of temperatures. The following function computes the standard deviation of temperatures from a given list L. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ std_dev(L) := sqrt((L-AVG(L)).(L-AVG(L))/lenght(L)); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Compute the standard deviation of temperatures in the list lst from 3.2. Use wxdraw2d to plot temperature curve. Add to the plot the average temperature and both +(standard deviation) and -(standard deviation) as horizontal lines. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: section start ] Linear Algebra [wxMaxima: section end ] */ /* [wxMaxima: input start ] */ kill(all); /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] Matrices and Vectors [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Run command load("eigen") always before computing with matrices. This makes a few essential functions available. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ load("eigen")$ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Matrices can be defined in Maxima using the command matrix. The command takes lists of equal length as arguments. These lists represent the rows of the matrix: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ A:matrix([0,2],[1,0]); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] A vector can be denoted in three alternative ways in Maxima. A column vector v can be defined in Maxima as follows: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ v:covect([5,-2]); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] A row vector u is defined using matrix command: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ u:matrix([1,-3]); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Third option for representing a vector is as a list: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ w:[3,-7]; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] The command transpose can be used to transform between row and column representations. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ transpose(v); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] A list can be tranformed into a row vector simply by using matrix(). [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ matrix(w); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] The command transpose gives the transpose of a matrix: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ transpose(A); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Matrix product is denoted with just a dot ".": [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ A.v; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] There is a linear transform L corresponding to every m x n -matrix C (L(v) = Cv). The kernel of L is the set of vectors v such that Cv = 0. Similarly, the image of L is the set of vectors Cv, where v is a vector. These sets cannot be computed in Maxima, but there are commands for finding basis vectors for both sets (or subspaces). Basis for the kernel of L is computed as follows: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ C:matrix([-2,-2,-4],[-3,0,-1]); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ nullspace(C); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Respectively a basis for the image is computed as: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ columnspace(C); /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] Determinant and trace [wxMaxima: subsect end ] */ /* [wxMaxima: input start ] */ kill(all); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] From linear algebra we remember two useful functions on matrices: determinant and trace. The determinant of a matrix A in Maxima is determinant(A). The trace of a matrix A is mat_trace(A): [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ A:matrix([2,-1],[-1,3]); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ determinant(A); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ mat_trace(A); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Also we might remember that the determinant of a matrix is equal to the product of its eigenvalues and that the trace of a matrix is equal to the sum of its eigenvalues. To this end, we recall next what eigenvalues of a matrix mean. [wxMaxima: comment end ] */ /* [wxMaxima: subsect start ] Eigenvalues [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Recall from linear algebra that eigenvalues of a matrix A are complex numbers lambda such that A*v = lambda*v for some nonzero vector v. If such lambda exists, then the vector v is called an eigenvector of A. Let's see how to compute this in Maxima (load("eigen") is required for this). [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ A:matrix([0,1],[1,0]); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] The command eigenvalues computes eigenvalues of the matrix and gives their multiplicities. Output is a list containing two lists. The first sublist contains the eigenvalues and the second sublist contains their multiplicities: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ eigenvalues(A); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ I:matrix([1,0],[0,1]); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ eigenvalues(I); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Eigenvectors of a given matrix can be computed using eigenvectors command. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ eigenA:eigenvectors(A); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ eigenI:eigenvectors(I); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] eigenvectors command returns the list of eigenvalues as the first sublist and the second sublist contains corresponding eigenvectors. Let's test that this is indeed the case: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ v:covect(part(eigenA,2,1,1)); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ v:covect([1,-1])$ /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ A.v; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ (-1)*v; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Eigenvalues are also solutions to the characteristic polynomial, that is lambda is an eigenvalue of A iff det(A - lambda*I) = 0, where is I is the identity matrix on appropriate size. Characteristic polynomial in Maxima is computed with command charpoly, which takes a matrix and a variable as an input (often chosen to be lambda, but here we chose x). [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ charPoly:charpoly(A,x); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ solve(charPoly,x); /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] Exercises [wxMaxima: subsect end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] There are three ways for representing vectors in Maxima: lists, row vectors and column vectors. In this exercise, we learn how to transform vectors from one form to another. Define vectors a = (1,2,3) as a column vector, b = (3,4,5) as a row vector and c = (5,6,7) as a list. Transform a to a row vector and a list. Transform b to a column vector and a list. Transform c to a column vector and a row vector. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] Use the matrix C from section 2.1. in this exercise (redefine it if needed). One way of thinking about the kernel of an linear transform is that it consists of all solution vectors v = (x,y,z) to a homogenous equation Cv = 0. However, the column vector Cv cannot be given as an argument solve command. Tranform Cv to a list cv. To solve Cv = 0 you must tranform this matrix equation to a system of equations. Use map("=", cv, [0,0]) to do this tranformation. Solve the equation Cv = 0 and compare the solution to output of the command nullspace. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] Find a basis to the kernel of the linear transformation correspondig to matrix A with rows (2,0,2), (2,1,1) and (2,2,0) (see equation (1) in the PDF). [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] This basis is "framed" by span command. How can you extract basis vectors under the span? Using the command part(e,j) you can collect jth part of expression e. Find the orthogonal complement of the kernel with command orthogonal_complement. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] Continuing previous exercise. Find the orthogonal complement of the image of linear transformation corresponding to the matrix A. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] Define matrix M with rows (1,e^(-a^2/2),1), (3,1+2/(a^2+1),5-a) and (2,0,e^(-a^2/3)) (equation (2) in the PDF), where a is a real parameter. What are the values of the parameter a such that M doesn't have an inverse matrix? Recall that a matrix has an inverse if and only if its determinant in nonzero. Find the maximum points of the determinant of M. Illustrate your solution by drawing a picture. Plot both the graph of the determinant as a function of a and the extreme points of the determinant (that is at least the zeros of the determinant and maximum value). [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] Given three vectors a, b and c in R^3, how can you use the determinant to check whether c is in the plane (subspace) spanned by a and b? Is c=[2,7,3] in the plane spanned by a=[1,5,2] and b=[1,-7,2]? [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] What is the smallest eigenvalue of the matrix A:matrix([1,3],[3,-2])? What is the corresponding eigenvector? [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] The matrix B:matrix([-3,1],[1,-2]) is symmetric and therefore its eigenvalues should be real and the eigenvectors orthogonal to each other. Find the eigenvalues and eigenvectors and check whether these properties indeed hold. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] (Continuation from the previous one.) The trace and the determinant of a matrix are the sum and product of its eigenvalues. Check that this is indeed the case for the matrix B of the previous exercise. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: section start ] Basics of Programming [wxMaxima: section end ] */ /* [wxMaxima: input start ] */ kill(all); /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] Conditional Statements [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Conditional statements are fundamental in any programming language, and so they are in Maxima. The simplest of conditional statements is the if-conditional: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ x:5; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ if x = 5 then "x is equal to 5" else "x isn't equal to 5"; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] This conditional checks, is a given condition true (here "x=5"). If the condition is true , then conditional statement returns the expression after the word then (here it's a string "x is equal to 5") and if the condition is false, then the expression after the word else is returned (here it's a string "x isn't equal to 5"). Change the value of x above and try running the conditional statement above again. The else part is optional in a conditional statement: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ if x > 0 then "x is positive"; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Commands depending on a conditional can be executed with if-conditionals: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ n:1; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ if n = 0 then wxplot2d(sin(z),[z,-5,5]) else wxplot2d(z^2,[z,-5,5]); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ x; n; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ if n = 0 then if x = 1 then y:1 else y:2 else if x # 1 then y:3 else y:4; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ y; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] The command "is" is used for checking the truth value of a conditional: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ is(1=1); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ is(2#2); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ is(log(5)>1.4); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ is(1=1.0); /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] Loops [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Along with conditional statements, loops are fundamental tools in programming. The basic idea behind loops is simple. Loops can be used to repeat commands multiple times. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ x:2; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ for i:1 thru 10 do x:2*x; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ x; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] The i above is called an index variable. While looping index variable runs through all integers on a given interval. The sum of first hundred natural numbers is calculeted as follows: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ n:100; sum:0; for i:1 thru n do sum:sum+i; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ sum; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] We get the same result with the usual sum formula: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ (n+1)*n/2; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] How can we sum only the natural numbers that are divisible by three? Conditional statements come to help! Divisibility by three can be verified with mod-function. For example, [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ mod(9,3); mod(10,3); mod(11,3); mod(12,3); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ n:100; sum:0; for i:1 thru 100 do if mod(i,3) = 0 then sum:sum+i; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ sum; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] H [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ list:[1,4,-5,3,-7,354,-1,21,-%pi,0,86,sqrt(2),34,-9,6]; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] To do this we need to find the number of elements in a list ... [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ length(list); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] ... and we need to know how to append two lists: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ append([1,2,3],[4]); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] We create a new empty list, where we collect positive numbers. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ new_list:[]; for i:1 thru length(list) do if list[i] > 0 then new_list:append(new_list,[list[i]]); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ new_list; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Maxima also supports while-loops. While-loops repeat command untill a given condition is satisfied: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ u:1; while u < 6 do u:u+1; u; /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] Exercises [wxMaxima: subsect end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] We would like to compute the sum of numbers a1,...,a10. If he numbers are given as elements of a list a in Maxima, this sum can be computed with command sum: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ sum(a[j],j,1,10); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Let's try another option. Initialize the sum as zero: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ s:0; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Now, the sum is computed with loop as follows: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ for j:1 thru 10 do ( s:s+a[j] ); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Define the list [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ lst:[[1,-8.3], [2,-8.5], [3,-3.8], [4,2.2], [5,8.9], [6,13.7], [7,16.5], [8,14.1], [9,8.8], [10,3.6], [11,-2.0], [12,-6.2]]; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] in Maxima. This list contains monthly averages of temperatures (first number in each element is the month and second the temperature). Compute the yearly average of temperatures using both mentioned methods. Use the command part to separate temperarures. Did you get the same result? Which option was more natural to you? [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] Let a be real number. Command if a > 0 then print("a is positive"); prints the text "a is positive" is a > 0 is true for the expression a. Consider the list lst of monthly average temperatures from previous exercise. Print those month-temperature pairs, where the temperature is positive. Use for-loops and if-conditionals. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] Continuing previous exercise modify your answer so that now instead of printing the pairs with positive temperature are collected to a new list. Initialize a list tmp:[]; Find out how command append works. Add pairs with positive temperature to tmp using append. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] There is an alternative way for finding the list from previous exercise. Define [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ s:0; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ f(l):=is(l[2]>s/12); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Apply the function f to the seventh element of the list lst. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] List of pairs of positive temperature is now found as follows: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ sublist(lst,f); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] How does the command sublist work? [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: section start ] Advanced Plotting and Drawing [wxMaxima: section end ] */ /* [wxMaxima: input start ] */ kill(all); /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] wxdraw2d [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Often command wxdraw2d used instead of wxplot2d to plot and draw more complicated pictures. [wxMaxima: comment end ] */ /* [wxMaxima: subsect start ] explicit [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Recall that plotting sin(x) with wxplot2d works as follows: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxplot2d(sin(x),[x,0,%pi])$ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] However, wxdraw2d requires following, if we want the same output: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxdraw2d(explicit(sin(x),x,0,%pi))$ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] The idea is that first we created object to be plotted or drawn with commands like explicit(). Then these objects are given to wxdraw2d, which executes the drawing. A graph of an ordinary function is always created with explicit(). [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ parabola:explicit(x^2,x,-1,1); curve:explicit(-(x+1)^3,x,-2,0); wxdraw2d( parabola, curve ); /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] implicit [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] An implicit graph means a solution set of a equation. For example, it can be a curve on a plane. Such objects can be with command implicit(). Implicit objects are given to wxdraw2d in the same manner as in previous example. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ heart:implicit((x^2+y^2-1)^3-x^2*y^3 = 0,x,-2,2,y,-2,2); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ wxdraw2d(heart)$ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Let's upgrade this drawing. Further adjustment separeted with commas can be added to wxdraw2d: - color=red; sets color as red - line_width=3; increases line width - proportional_axes=xy; lengths of x-axes and y-axes are equal [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxdraw2d( color=red, line_width=3, heart, proportional_axes=xy )$ /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] polar [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Creating curves defined in polar coordinates is done with polar() (recall what polar coordinates are, if needed). [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ lemniscate: polar(sqrt(cos(2*theta)), theta, 0, 2*%pi); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ wxdraw2d(lemniscate)$ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Upgrading the drawing: - xrange=[-1.5,1.5], yrange=[-1.5,1.5]; defining x and y ranges - xaxis=true, yaxis=true; both axes are included - nticks=300; improves drawing accuracy [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxdraw2d( proportional_axes=xy, xrange=[-1.5,1.5], yrange=[-1.5,1.5], xaxis=true, yaxis=true, nticks=300, lemniscate )$ /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] parametric [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Sometimes curve is given in parametric form, that is its x- and y-coordinates are functios of some variable (for example, functions of time). Parametrization can be thought of as drawing path or a curve. If function to be drawn is given in parametric form, it can be created using parametric(). [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ circle:parametric(cos(t), sin(t), t, 0, 2*%pi)$ /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ cornu_spiral:parametric( fresnel_c(t), fresnel_s(t), t,-5,5)$ /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ wxdraw2d( proportional_axes=xy, nticks=300, color=red, cornu_spiral, color=blue, circle )$ /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] Points [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Creating a dicrete set of points is simply done with command points(). Let's draw points (1,1), (2,-3), (-4,5), (-1,2) ja (0,3). [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxdraw2d(points([[1,1],[2,-3],[-4,5],[-1,2],[0,3]]))$ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] All points aren't showing. We increase x and y ranges. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxdraw2d( points([[1,1],[2,-3],[-4,5],[-1,2],[0,3]]), xrange=[-5,4], yrange=[-4,7] )$ /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] Combining [wxMaxima: subsect end ] */ /* [wxMaxima: input start ] */ kill(all); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Combining different plotting objects gives stylish pictures. The command wxdraw2d takes as many object and adjustments as needed. It's reasonable to put different draw commands on different lines to improve readability. Elements introduced so far can be combined freely. Commands are always separeted by commas. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Next we draw a picture, where the graph of cos(x) is drawn with red on [0,2pi] and x^2+1 is drawn is drawn with blue on [-2,2]. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxdraw2d( color=red, explicit(cos(x),x,0,%pi), color=blue, explicit(x^2+1,x,-2,2) )$ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Think about it this way: - take a red brush: color=red - draw explicit graph: explicit(cos(x),x,0,%pi) - take a blue brush: color=blue - draw another explicit graph: explicit(x^2+1,x,-2,2) [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Caution: Order matters! The color of a brush doesn't change unless changed! [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] We add points to previous picture and change colors and styles occasionally. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] - point_type=circle; changes points to be small circles - point_size=10; adjusts the size of points - points_joined=true; connects points that are draw at same time [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxdraw2d( color=red, explicit(cos(x),x,0,%pi), color=blue, explicit(x^2+1,x,-2,2), points([[1,1],[1,2]]), color=green, points([[0,1],[0,2]]), point_type=circle, points_joined=true, points([[2,2],[3,3],[2,4]]), point_size=10, color=red, points([[0,0]]) )$ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Some of the commands change settings: - points_joined=true - color=red - etc. On the other hand, some of the command draw with present settings: - explicit - points - implicit - etc. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Also, there is general settings such as size/dimensions/stc. The place of these commands doesn't affect the picture. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Next, we draw into a same picture solutions of x^2+y^4=3 with green and the curve (t^2,t) with blue on [0,10]. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxdraw2d( color=green, implicit(x^2+y^4=3,x,-10,10,y,-10,10), color=blue, parametric(t^2,t,t,0,10) )$ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Let's rescale the picture more reasonably. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxdraw2d( xrange=[-2,2], yrange=[-2,2], color=green, implicit(x^2+y^4=3,x,-10,10,y,-10,10), color=blue, parametric(t^2,t,t,0,10) )$ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] The green curve is rough. Let's make Maxima use more precision. From the manual we see that the value of ip_grid can be changed. The blue curve gets better, if we increase nticks. Now, the picture looks nicer, but it takes a bit longer to draw it. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxdraw2d( xrange=[-2,2], yrange=[-2,2], color=green, ip_grid=[200,200], implicit(x^2+y^4=3,x,-10,10,y,-10,10), color=blue, nticks=200, parametric(t^2,t,t,0,10) )$ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Where do these curves intersect? Solving the intersection involves a system of polynomial equations. Recall that systems of polynomial equations can be solved with algsys. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ solutions:algsys( [ x^2+y^4=3, x=t^2, y=t ], [x,y,t] ); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] We find four solutions. There is only one intersection point in the picture. Clearly t must be a positive real number. Thus the first solution is correct. We pick this solution from the list solutions. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ solutions[1]; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] The point (x,y) we are looking for can be extracted with part-function: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ intersectionpoint:[part(solutions,1,1,2),part(solutions,1,2,2)]; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] We plot this point into the picture by drawing a larger and a smaller red circles. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxdraw2d( xrange=[-2,2], yrange=[-2,2], color=green, ip_grid=[200,200], implicit(x^2+y^4=3,x,-10,10,y,-10,10), color=blue, nticks=200, parametric(t^2,t,t,0,10), color=red, point_type=circle, point_size=5, points([intersectionpoint]), point_size=1, points([intersectionpoint]) )$ /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] wxdraw3d [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Commands wxdraw3d and draw3d draw three dimensional pictures. Principles of drawing 3D pictures is the same as drawing 2D pictures with wxdraw2d. For example, a three dimensional explicit graph: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxdraw3d( explicit(x^2+5*sin(y),x,-4,4,y,-6,6) )$ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Advantage of draw3d compared to wxdraw3d is that draw3d pictures can be rotated: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ draw3d( explicit(x^2+5*sin(y),x,-4,4,y,-6,6) )$ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Style of the picture can again be adjusted with a lot of settings: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxdraw3d( enhanced3d=true, wired_surface=true, explicit(x^2+5*sin(y),x,-4,4,y,-6,6) )$ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] For example, parametric plotting works as follows: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ expr_1: 5*cos(x)*(cos(x/2)*cos(y) + sin(x/2)*sin(2*y) + 3.0) - 10.0$ expr_2: -5*sin(x)*(cos(x/2)*cos(y) + sin(x/2)*sin(2*y) + 3.0)$ expr_3: 5*(-sin(x/2)*cos(y) + cos(x/2)*sin(2*y))$ kleinbottle: parametric_surface(expr_1,expr_2,expr_3,x,-%pi,%pi,y,-%pi,%pi); draw3d( enhanced3d=true, wired_surface=true, kleinbottle ); /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] Exercises: [wxMaxima: subsect end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] Draw the heart and lemniscate from examples into a same picture. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] Draw the following into a same picture using wxplot2d: - Graph of cos(sin(x)) with blue on interval [-2,0] - A green circle who's radius is 1 and center point the origin - Graph of 1+x^2 with blue on interval [0,2] - A big point (0,1) with red [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] Draw a circle in multiple ways (to several pictures or all at once): - using implicit() (as a solution set to an equation) - using explicit() (you will need two graphs) - using parametric (boundary curve with sine and cosine) - using polar coordinates (radius is a constant!) - as a point that is of circle type and large [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] How many solutions there are to system x^2+y^6=6, x^3-2y=1? Draw a picture and deduce from it. Find solutions with a command of your choice. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] Draw any surface in three dimensions using wxdraw3d. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] Draw the curve y=sin(x^2)-x^3 and its tangent at x=2. Highlight the tangent point and the point where the tangent line intersects the x-axis. Is this related to Newton's iteration, if so then how? [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] As in previous exercise, but create a function that draws the picture, when the expression, variable and its value are given. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] Let us look at the graph of f(x,y) = x*sin(y) from different angles. Plot the graph using draw3d and examine it by rotating. Compare this to the picture given by wxdraw3d. Do you understand the output of draw3d better or worse than the output of wxdraw3d? What new can you see using draw3d? [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] Creative drawing. Draw a picture of a flower. Use red for the leaves and green for the stalk. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: section start ] Recap [wxMaxima: section end ] */ /* [wxMaxima: input start ] */ kill(all); /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] This last section contains a couple of relatively simple recap exercises and concludes the collection of compulsory problems. The elective ones are given in a separate file. [wxMaxima: comment end ] */ /* [wxMaxima: subsubsect start ] Trouble with cosines [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] The command acos(cos(x)); should return x. But it doesn't. Why not? Is the situation any different if the order of the two functions is reversed? Explain with plots and words and whatever makes sense to you. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] Parts of an equation [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] The part function can be used to collect parts from any list, any expression or basically from anything. Name the equation [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ equation:x^2-y^2=sin(t-cos(x))+log(2+%e^3); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Use the command part(equation,...) to collect the equalty sign "=", the variable "t" and the exponent "3". [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] Adding a story around calculations [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] Execute the following commands in order. Add comments in between to explain what is done and what the result of the final command [c,b] means. What are these two numbers? Do not calculate anything new, just explain what the given calculations mean. What was the problem being solved here? [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ kill(all); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ f:x-x^2*sin(x)/log(x); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ wxplot2d(f,[x,2,7]); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ df:diff(f,x); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ wxplot2d(df,[x,2,7]); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ zero:find_root(df,x,4,6); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ a:subst(2,x,f),numer; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ b:subst(zero,x,f),numer; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ c:subst(7,x,f),numer; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ [c,b]; /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] What about here? [wxMaxima: subsubsect end ] */ /* [wxMaxima: input start ] */ kill(all); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Read this example and execute the commands, and answer to the questions in the end. The task is to find the extreme values of sin(x) + log(x) on the interval [1,10]. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] First we define the expression of the function: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ expression:sin(x)+log(x); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Compute the derivative: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ dexpression:diff(expression,x); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] As we know the extreme values can be found from the ends points of the interval [1,10] or from the zeros of the derivative. Next, we draw a picture of the function and its derivative: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxplot2d([expression,dexpression],[x,1,10]); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] The picture tells us that one of the zeros of the derivative is between 1 and 3. We use find_root to find this zero and name it as a: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ a:find_root(dexpression,x,1,3); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Another zero of the derivative is on interval (4,5) and third is on (7,9) [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ b:find_root(dexpression,x,4,5); c:find_root(dexpression,x,7,9); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Extreme values can be achieved at the end points, so we give names to these as well. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ d:1; e:10; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Next, we evaluate the values of the function at these points and name the values with capital letters: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ A:ev(expression,x=a); B:ev(expression,x=b); C:ev(expression,x=c); D:ev(expression,x=d); E:ev(expression,x=e); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Comparing these numbers we find the maximum and minimum values of the function and the points where these values are achieved. To finish we draw a stylish picture of the function, its derivative, zeros of the derivative and extreme value candidates: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxdraw2d( xrange=[0.9,10.1], yrange=[-1,4], xaxis=true, color=blue, explicit(expression,x,1,10), color=red, explicit(dexpression,x,1,10), color=green, points_joined=true, point_size=0, points([[a,0],[a,A]]), points([[b,0],[b,B]]), points([[c,0],[c,C]]), points([[d,0],[d,D]]), points([[e,0],[e,E]]), color=black, points_joined=false, point_type=plus, point_size=2, points([[a,A],[b,B],[c,C],[d,D],[e,E]]) ); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] What is the value of x, where the function achieves its minimum value? What is the maximum value of the function on interval [1,10]? Give answers as approximations or as variable names. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] Extreme values [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] Find the extreme values of function f(x) = cos(x) - log(x) on the interval [1,7]. Present your computations graphically. Use the previous exercise as a guide-line. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] Solve and plot [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] Draw the circle x^2+y^2=7 and the line x-2y=3 in the same picture. Solve the intersection points algebraically, without numerical approximation. Add these points to your drawing. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsubsect start ] Your favorite exercise [wxMaxima: subsubsect end ] */ /* [wxMaxima: comment start ] Choose an exercise from another mathematics course (calculus or linearalgebra will do just fine). Explain the exercise and solve it using Maxima. Do you get same result using Maxima and by hand. Was it easier to use Maxima or do it by hand in your situation? [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] Feedback [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Feecback is important for developing the course further. Please answer the following questions in either language: Approximately how many hours did you spend Kuinka monta tuntia suunnilleen käytit kurssin suorittamiseen yhteensä? (answer/vastaus) What should have been explained better in the lectures or the exercise files? Mitä olisi pitänyt selittää paremmin luennoilla tai tehtävänannoissa? (answer/vastaus) What was the most frustrating aspect of the course? Mikä kurssilla oli turhauttavinta? (answer/vastaus) What worked so well that we should continue doing the same in future implementations? Mitkä asiat kurssin toteutuksessa toimivat niin hyvin että niistä kannattaa pitää kiinni tulevissa toteutuksissa? (answer/vastaus) Would it have been useful to be able to complete this course more flexibly at any time of the year? Olisiko ollut hyödyllistä pystyä suorittamaan kurssi joustavammin mihin aikaan vuotta tahansa? (answer/vastaus) Free feedback? Vapaata palautetta? (answer/vastaus) [wxMaxima: comment end ] */ /* Maxima can't load/batch files which end with a comment! */ "Created with wxMaxima"$