/* [wxMaxima batch file version 1] [ DO NOT EDIT BY HAND! ]*/ /* [ Created with wxMaxima version 17.10.0 ] */ /* [wxMaxima: title start ] Symbolic computing Exercise package B [wxMaxima: title end ] */ /* [wxMaxima: comment start ] Author: X E-mail: x.x@x.x [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Instructions: Add your details above and in the file name as in package A. To complete exercise package B you must solve every exercise as instructed. If you can't make something work, turn to teachers of the course for help. If you're not able to finnish an exercise in time, you're required to explain why. When answering questions remember to comment your calculations. Commenting improves readability and is in fact one of the evaluation criteria. Some formulas and functions where not included in exercises in this file. Missing information is available in the document SLB-Formulas.pdf. The equations are numbered as (1), (2), (3), ... Good luck! [wxMaxima: comment end ] */ /* [wxMaxima: section start ] More syntax [wxMaxima: section end ] */ /* [wxMaxima: subsect start ] Special symbols [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] ; semicolon ends a command $ dollar sign ends a command. However, it works a bit differently from ";" commands ending with $ don't print anything as an output to the user % percent sign: output of last calculation , comma works as an separator, for example commas are used between elements of a list and between arguments of a function . dot: decimal point; products of vectors and matrices : colon: assigning a value to a variable = equality: equalities := colon-equality defines a function ( ) ordinary brackets indicate arguments of a function; multiple commands a single input row; ordering operations [ ] square brackets: lists, vectors; indexed variables or functions; an index pointing to an element of a list { } curly brackets denote sets ' apostrophe prevents the value of the next symbol from being evaluated (cf. differential equations) '' two apostrophes (not a quotation mark) forces evalution of the next symbol " quotation mark: defining string /* */ backslash and multiplication sign: adding comment into input cells: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* This is a comment in an input cell */; /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] Constants and functions [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Names of universal constants start with a percent sign in Maxima. These should be familiar, at least when you see the numerical forms. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ constants:[%e, %gamma, %phi, %pi, %i, minf, inf]; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ float(constants); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] sqrt, exp, log (logarith to base %e i.e. natural logarithm; others don't exists); trigonometric functions: sin, cos, tan cot, sec, csc; inverses of trigonometric functions (arcus functions): asin, acos, atan, acot, asec, acsc; hyperbolic functions: sinh, cosh, tanh, coth, sech, csch; area functions: asinh, acosh, atanh, acoth, asech, acsch; [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Without the percent sign e and pi and the rest are treated as variables, not the constants. Beware! [wxMaxima: comment end ] */ /* [wxMaxima: subsect start ] What you see and what Maxima knows [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] As in every programming language, so in Maxima there is the consept of variables familiar from mathematics. Variables can be thought of as user named objects to which it's possible to assign a value. Benefit is that it's possible to refer to this value by simply writing the name of the variable in later computations. Assigning values to variables is done with a colon ":" [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Assigning the value 7 to variable named cat [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ Cat:7; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ Cat^2; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] The percent sign indicates to the last executed output cell. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ %; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Previously executed inputs and outputs can be refer to with their tags (%i1, %o1, etc.). wxMaxima shows these reference tags on the left side of output and input cells. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ %i4^4; %o3^3; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] However, do NOT use these reference tags, since if not used carefully they might not work after closing and reopening a file. In fact, any reference with a percent sign is considered wrong in this course. Name your variables explicitely and use names for referencing. A great deal of confusion is avoided this way. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] The value of a variable can be modified later: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ Cat:1 + %pi; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Delete the cells where the variable Cat was assigned values 7 and 1+%pi. To delete a cell, first select it by either dragging your mouse across it or clicking the left side of the cell, and then press delete or backspace. Let's ask the value of "Cat" again: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ Cat; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] The value of the variable stays unaltered even though its definition was deleted. This is because Maxima kernel remembers the variable even though its definition was erased from the interface wxMaxima. Knowledge of variables in the kernel can be deleted with the function "kill": [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ kill(Cat); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ Cat; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] All that's defined can be deleted as follows: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ kill(all); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] What you see in wxMaxima is not necessarily what Maxima knows. [wxMaxima: comment end ] */ /* [wxMaxima: subsect start ] Getting help [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Often, you might hit a brick wall when learning Maxima: Either you don't know what command to use next or you don't know how a given command works. For these situations there is Maxima help manual in wxMaxima. The manual can be found from menu: Help -> Maxima help. Another option is to use google, which might be even faster and/or more comprehensive. You may also turn to the teacher of the course, if you feel overwhelmed. There are a few commands in Maxima for trying to find help: [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] A list for existing examples can be found with command example(); For example, examples of usage of command diff can be found with example(diff); Command apropos("diff"); gives a list of commands that contain the word diff. Command describe(diff); or equivalently command ? diff; gives explanation from the manual associated with the command diff. Command describe(diff, inexact); or equivalently ?? diff; gives a manu from diffenrent parts of the manual. [wxMaxima: comment end ] */ /* [wxMaxima: section start ] Basic drawing [wxMaxima: section end ] */ /* [wxMaxima: subsect start ] plot2d and wxplot2d [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] The window you now have in front of you is wxMaxima, a graphic interface to Maxima. The interface wxMaxima introduces some new commands starting with the prefix "wx-", and they are all related to drawing. Evaluate the following cell, then close the plot window and change the command name "plot2d" to "wxplot2d" and evaluate again. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ plot2d(sin(x),[x,0,2*%pi]); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] The command plot2d produces the plot in an external window. Unfortunately you have to close the window before proceeding; wxMaxima will not accept any input while there is a plot window. If there is a plotting or drawing command like this, evaluating all cells of a Maxima notebook is halted. On the other hand, the command wxplot2d draws the plot within the wxMaxima window itself and you can continue working and looking at the plot. If you evaluate all cells of a notebook, all the plots are done without any unnecessary halts. The two commands plot2d and wxplot2d have exactly the same syntax. The wx-commands are not included in Maxima's help; therefore to get help with drawing within this window, you must look at the help for "plot2d" and then use those instructions but change the command name to "wxplot2d". IMPORTANT NOTICE: All plots and drawings in returned exercises must be made with the wx-prefixed commands which draw in the wxMaxima window unless spefically instructed otherwise. [wxMaxima: comment end ] */ /* [wxMaxima: subsect start ] Syntax [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] The two plotting commands we saw take two arguments: 1. the expression or list of expressions to be plotted 2. the list [variable, start, end] For example, we used wxplot2d(sin(x),[x,0,2*%pi]) above to plot the expression sin(x) as a function of x as it ranges from 0 to 2pi. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] You can plot several expressions by giving them as a list. [wxMaxima: comment end ] */ /* [wxMaxima: subsect start ] Exercises [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Plot a second degree polynomial of your choice on such a range that you see its minimum or maximum. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Plot both sine and cosine in the same plot by taking the example above and replacing sin(x) with [sin(x),cos(x)]. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Give a name to the expression x^5-100x^2+6x+1. Plot it on different ranges to see how it behaves. How many (real) zeroes does it seem to have? [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Draw the graph of the function (1) in the PDF on interval [15,20]. What can be said about the value of the limit of (1) at infinity. First, figure out the limit based on the graph. Determine then the exact limit (using command limit). Why do the graph and the computation give a such different results. It might help to draw a new graph on an interval [1,13] for example. Explain in a comment what is going on. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: section start ] Differentiation and integration [wxMaxima: section end ] */ /* [wxMaxima: subsect start ] Differentiation [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] The basic differentiation command is diff and it takes two (three) arguments: 1. the expression to be differentiated 2. the variable with respect to which we differentiate 3. the order of differentiation (optional) [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ diff(x^6,x); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ diff(x^6,x,2); diff(diff(x^6,x),x); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ diff(x^6,x,6); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Leaving out the variable is possible, but then Maxima computes something else: the differential rather than the derivative. We will not be using this concept in this course, so always remember to include the variable. [wxMaxima: comment end ] */ /* [wxMaxima: subsect start ] Symbolic and numerical integration [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] The basic command for symbolic intergration in Maxima is "integrate". To compute indefinite integrals (integral functions) two arguments must be given. 1. the expression to be integrated 2. the variable with repect to which we integrate To compute definite integrals additional arguments must be given. 3. the start point of the interval 4. the end point of the interaval [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ mcos:integrate(sin(x),x); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ diff(mcos,x); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ integrate(sin(x),x,0,%pi/2); /* [wxMaxima: input end ] */ /* [wxMaxima: answer start ] */ ; /* [wxMaxima: answer end ] */ /* [wxMaxima: comment start ] Something seems to be missing from the first example. That's right the constant of integration. Be careful: if needed, you must add the constant yourself. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Infinity and minus infinity are represented as inf and minf respectively. Improper intergrals can be computed using inf or minf (or both) as an end point of the interval. [wxMaxima: comment end ] */ /* [wxMaxima: subsect start ] Exercises [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] In these exercises we learn diffenrentiation and integration using Maxima. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] In Maxima the command diff is used for differentiation. Get familiar with syntax or select Calculus -> Differentiate from Maxima's menu. Differentiate a) f_1(x) = x^5 - 5x + 4 with respect to x. b) f_2(x) = 2z^2log(z) - z^2 with respect to z. c) f_3(a,b) = sin(ab) + sin(a)sin(b) first with respect to a, then with respect to b. d) Find the fifteenth derivative of f_4(y) = sin(pi*y) with respect to y. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Differentiate f(x) = sin(x*log(2x)). [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Create following functions 1 and 2 in Maxima. You may assume that the input expression depends only on x (if you like you may consider the general case). 1) Function deriv_subst which takes an expression as an argument and returns the value of its derivative at x=5. 2) Function square_integral which takes an expression as an argument and return the integral of this expression with repect to x on interval [0,1]. Test your function with input 1/(1+x). [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Try the command integrate. Check by integrating that the answers in the first part of these exercises (a-d). Further, compute the integral of sin^3(x) ------------------- sin^3(x) + cos^3(x) on interval [0,2*pi]. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Compute the indefinte integral of function e^(-ax)sin(x) and the definite integral of e^(-ax)sin(x) from 0 to infinity (infinity in Maxima is inf). For the indefinite integral to converge the constant a must be positive. Assumptions can be given to Maxima with command assume(a>0). Compute the integral above again. Assumptions may be deleted with command forget(facts());. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] From above exercises we notice that integrate works for definite integrals. The command integrate works only if Maxima is able to compute a reasonable integral function for the integrable. Try to compute the integral of x ---------- 2 + sin(x) on interval [1,3]. This shouldn't work. Fortunately, Maxima has tools for numerically computing integrals as well. Try computing the requested integral with the command "romberg" that has the same syntax as "integrate". [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Not every function has an integral function representable as an elementary function. Try what happens when trying to integrate e^(-x^2)cos(x). However, check what Maxima gives as the derivative of this function. How does the system variable erfflag influence the output? Also, compute the definite integral of e^(-x^2)cos(x) from -infinity to infinity. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Find exact values for integrals of e^(-x) on intervals [0,infinity] and [0,10]. Also find approximations for the integral on the second interval. Compute the integral of e^(-x) on [0,10] using Rombgerg's method. There's a command in Maxima named romberg. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Compute double integrals of f(x,y) = 1 + (x-y)/(x+y)^3 in both orders. For clarity, integrals to be computed are available in (*) cf. (2) and (3). What do you notice? Recall Fubini's theorem. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Compute the triple integral of yze^x, where -1 <= x <= 1, -1 <= y <= 0 and 0 <= z <= 1. (cf. (*) eq. (4)) [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Let us declare a parameter: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ a:1; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Draw a plot of the function cos(x/3) on the interval [-2,5] and its tangent line at the point x=a. (Explain how you get an expression for the tangent line!) Then change the parameter a by altering the command above and rerunning it, and redraw. Making adjustments is easy if you use parameters! [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: section start ] Basics of lists [wxMaxima: section end ] */ /* [wxMaxima: subsect start ] Creating lists [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Maxima supports structures called lists. A list is something that represent a set of objects in a fixed order. Elements in a list are indexed starting from 1. That is the first element in a list is associated with index value 1, the second element is associated with value 2, etc. Benefit from using lists is that they enable saving multiple objects in a one variable. For example, you might not want to store daily average temperatures from year 2019 in 365 individual variables. Lists are created as follows: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ list1:[1,2,3]; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Lists can contain other lists: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ list2:[1,2,list1]; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] or basically anything [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ list3:["This is a string", cos(%e), Fish]; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Objects in a list are refed to with their index numbers. For example: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ list1[1]; list1[2]; list1[3]; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ list2[3]; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ list3[1]; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Longer lists with repeating patterns can be created using "makelist": [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Many functions can be directly applied to a list in order to compute the value of a function at every element of a list individually: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ cos([0, %pi/4, %pi/2, %pi/6]); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ diff([1,x,x^2,x^3,x^4,x^5],x); diff(makelist(x^i,i,0,5),x); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] It's even possible to assign values to multiple variables at once using lists: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ [u,w,v]:[1,%e,diff(x^2,x)]; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ u; v; w; /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] Adding points to plots [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] The plotting command plot2d and wxplot2d come with all sorts of additional settings. For example, it's possible to change the style of drawn lines and points: [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] To define style of plots use additional option of sort [style,lines,lines,points] [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] To change the appearance of discrete points us an option of sort [point_type,asterisk] [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Many additional adjustment can be found from the Maxima manual for example. Here's some options. No need to memorize them now or to find out what every single option changes. We will come back to this in the third exercise package. Feel free to exepriment, though! [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxplot2d ( [2*x-1,x^2 - 1,[discrete,[[0,-1],[2,3]]]], [x, -3, 3], [style,lines,lines,points], [color,blue,green,red], [point_type,asterisk], [box, false], [legend,false], [yx_ratio, 1], [axes, solid], grid2d, [xtics, -2, 4, 2], [ytics, -6, 2, 6], [label, ["y = x^2 - 1", -2, 3.5],["y = 2x - 1", -2.4, -3.5]], [title, "Intersection points of a parabola and a line"] )$ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Exercises: In these exercises we learn plotting in Maxima. Get familiar with function plot2d and draw a graph of some function using it. Now, do the same with wxMaxima's wxplot2d command. Both commands have same syntax. What's the difference between plot2d and wxplot2d? Find out how to draw a picture of a discrete data set. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Let the data be given as a list [[1,2.94],[2,4.33],[3,5.18],[4,6.14],[5,6.52]]. Define this data in Maxima and plot it. The plot shows that the data points are almost on a graph of function c*sqrt(x), where c is a constant. Plot this function into same picture as the data. Try which value of c gives a good approximation. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Tips: To plot a discrete data set you might want to add [style, points] setting into the plot command. When plotting points and graphs into a same picture, settings should be of sort [style, points, lines]. [wxMaxima: comment end ] */ /* [wxMaxima: section start ] Solving equations [wxMaxima: section end ] */ /* [wxMaxima: subsect start ] Single equations [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Maxima can be used to solve different types of equations. Here we learn some useful commands for this. First, let's try to find roots of polynomials. It's recommended to first draw a graph of the polynomial. The graph already gives an approximation for roots. Run following cells in wxMaxima: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ poly : x^3 +x^2 -3*x +1; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ wxplot2d([poly], [x,-5,5])$ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] This graph doesn't suffice, since the y-scale is too large. The y-scale can be reduced with following command: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxplot2d([poly], [x,-5,5], [y,-5,5])$ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] We see that the polynomial should have three real roots. Since this polynomial is of third degree, it has three roots atmost! Let's try factorizing the polynomial with the command factor: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ factor(poly); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] We find a root automatically, but Maxima doesn't want to factorize the second degree term into linear ones, since there would be coefficients that are outside of the integers and the rationals. Propably we would be able to compute remaining roots from the quadratic formula, but can we find them convenietly using Maxima. For this purpose there is the command "solve": [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ solve(poly = 0, x); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] It works! Solve requires an equation and a variable for reference on how it should be solved. For simple expressions finding zeros can be accomplished with: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ solve(poly); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Recall basic computing with Maxima and solve following problems: 1) Factorize x^5 + 3x^4 + x^3 + 3x^2 - 2x - 6. What are real roots of this polynomial? [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] 2) Simplify sqrt(4x^2 + 12x + 9). Is the output "correct"? [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] 3) Define expressions 2x^2 - 1 + 2xsqrt(x^2 - 1) and (1/2)(e^y + e^(-y)). Substitute (subst) the second expression into the first. Simplify output (radcan should work here). [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Solve following three exercises with the solve command: A) Find the roots of x^5 - 10*x^4 + 24*x^3 + 22*x^2 - 73*x - 60 [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] B) Find the points of intersection of polynomials 4*x^4 + 40*x^2 + 4 and x^4 + 21*x^3 - 3*x^2 + 29*x [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] C) Solve the equation |x^2 - 4*x| = 1 [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Solve-command is mostly applicable for solving polynomial and other algebraic equations: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ solve(sqrt(x)-2=0,x); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Command above works, but next one won't: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ expression1:sin(x)-x/3; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ solve(expression1=0,x); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Let's draw a picture [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxplot2d(expression1,[x,-10,10]); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Thus we should have at least three zeros. Let's try solving them with Maxima's command "find_root": [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ find_root(expression1,-5,5); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Notice how the command find_root takes an expression as an input as well as an interval on which to iterate for a root. The command always returns a root (an approximation). In this case x=0. Let's try iteration starting from different interval: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ find_root(expression1,-10,-3); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Maxima throws an exception, which actually tells us what iteration is based on: If a continuous function has values of different signs on the iteration interval, then without a doubt there is a root on the interval. To learn from the graph, let's try on a better interval: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ find_root(expression1,-5,-1); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Now, we succeeded! Practice again with this command and solve the following exercise. Remember that drawing a graph is helpful when iterating! D) Find all solutions to equation log(x) = x - 2*sqrt(x) + 1. You may (and must) assume that x > 0. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] Numerical solutions [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] The command find_root often works well. However, it isn't enough with all expressions. There is another option for finding roots called Newton iteration. This method can be utilized in Maxima, but first we must load the the function: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ load(mnewton); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Now, the function mnewton can be used in Maxima! Using it requires an expression, a variable and a number. This number represents an initial guess. The initial guess is reasonable to choose close to a potential root: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ expression1; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ mnewton(expression1,x,0.1); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ mnewton(expression1,x,1); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ mnewton(expression1,x,2); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ mnewton(expression1,x,3); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ mnewton(expression1,x,5); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] As noticed, depending on the initial value mnewton produced an approximation of a root. Or it reported that the initial value wasn't sufficient. Let's additionally try how Maxima finds solutions to a simple system of equations: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ solve([x+3*y=1,y-4*x=9], [x,y]); /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] Exercises [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Find the solution to x^3 = x + 2cos(x). Use both commands find_root and mnewton. To use mnewton you must load a package mnewton (load(mnewton)). It definitely pays off to draw some plots of the situation. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] There is more commands for solving polynomial equations. For example, algsys, nroots and allroots. Explain what these commands do. Solve x^5 + 7x + 1 = 0 using one of these commands. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Maxima can handle systems of equations as well: Solve following system of equations using algsys command: x^2 + y^2 = 3, y^2 = x^3 - 3x + 1. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Draw graphs of f(x) = e^xsin(2x) + e^(x/2) and its derivative f'(x). Find a solution to f'(x) = 0 using an approximation method, for example find_root. The graph of the derivative comes in handy. Compute the value of f(x) at the (approximate) root of f'(x) you found. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Determine a solution to 1 + x + e^xsin(x) = 0 with Newton's interation. That is with the command mnewton. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] Extreme value problems [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] From highschool and calculus courses we remember that a extreme values of an differentiable function can be found from zeros of the derivative. What we have learned so far allows us to differentiate and solve zeros. Thus we can solve following questions. Support your solution with pictures! E) Find the extreme value points of x^3 + x^2 - 3*x + 1 (the polynomial should still be assigned to variable named poly). [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] F) Find global maximum and minimum values of x + 6*sin(x) on interval [0,7]. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] G) Find local extreme points of x^5 + x^2 - x - 2 + 2*cos(x) + sin(x). Tip: try drawing a picture with very small y-scale, so that you see what really happens. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Find roots, local extreme values and both the global minimum and the global maximum of f(x) = log(x)/x^2 - e^(-(x-3)^2). Also, determine the limit of f(x), when x approaches +infinity. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: section start ] Problems [wxMaxima: section end ] */ /* [wxMaxima: subsect start ] Help [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Use Maxima's help feature to find a way to solve an ordinary differential equation (often abbreviated to ODE). You can try several if there are several. Find all functions f which satisfy f'(x) = f(x) for all x. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Initial value problem asks to find a solution to a differential equation with given initial restriction. For example, f'(x) = f(x), f(0) = 1 is an initial value problem. How to solve an initial value problem in Maxima? Solve the initial value problem f'(x) = f(x), f(0) = 1 using Maxima. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* [wxMaxima: subsect start ] Plot of polynomial [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Let us plot a simple polynomial: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxplot2d(x^2-2x-3,x,-4,4); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Why does this not work? Explain the problem and fix it. [wxMaxima: comment end ] */ /* [wxMaxima: subsect start ] Plot of differential [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Let us plot the function sin(x) and its derivative: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ kill(all); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ sine:sin(x); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ dsine:diff(sine); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ wxplot2d([sine,dsine],[x,-%pi,%pi]); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] The picture is wrong! Explain how the plot is wrong, what causes the problem, and fix it. [wxMaxima: comment end ] */ /* [wxMaxima: subsect start ] Plot of Gaussian [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Let us draw the bell curve: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxplot2d(e^(-x^2),[x,-5,5]); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] What does the error message say? What is wrong with the command? Fix it. [wxMaxima: comment end ] */ /* [wxMaxima: subsect start ] Evaluation [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] Let us compute the value of x^2-5 at x=3: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ polynomial:x^2-5; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ polynomial(3); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Why does this not work? Give two different ways to fix this. [wxMaxima: comment end ] */ /* [wxMaxima: subsect start ] Numerical error [wxMaxima: subsect end ] */ /* [wxMaxima: comment start ] In principle Maxima is ment for symbolic computation, so if not separately asked, Maxima doesn't compute with approximations at all. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ Variable1: %pi; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ cos(Variable1); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] As we have seen before, approximations can be asked with predefined function "float". [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ Variable2: float(Variable1); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ cos(Variable2); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Maxima computes approximations with precision up to 16 decimal places. This means that errors are often fairely small, when computing with approximations. However this isn't always the same as computating with exactly right numbers. Here "often fairly small" doesn't mean "always very small". When dealing with approximations, the user is reponsible for interpreting Maxima's calculations and sometimes even decide if the error made by Maxima significant or not. When drawing graphs Maxima always turns to approximations! Here is an example where the error can be surprisingly significant: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ kill(all); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Define six expressions as follows: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ l_a:u*v*w*x*y; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ l_b1:(u*v*w)^(1/3); l_b2:(v*w*x)^(1/3); l_b3:(w*x*y)^(1/3); l_b4:(u*x*y)^(1/3); l_b5: (u*v*y)^(1/3); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] The number l_a is a product of five variables. Each of the numbers l_b1,...,l_b5 is a product of three cubic roots of variables so that the cubic root of each variable appears exactly three times. That is if all five expressions are multiplied together, we should get the original expression l_a. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ l_b1*l_b2*l_b3*l_b4*l_b5; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ l_a - l_b1*l_b2*l_b3*l_b4*l_b5; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] The difference is zero as it should be. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] What happens if we try this with numerical values: [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ [u,v,w,x,y]:[7919.0, 7927.0, 7933.0, 7937.0, 7949.0]$ /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ l_a:u*v*w*x*y$ /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ l_b1:(u*v*w)^(1/3)$ l_b2:(v*w*x)^(1/3)$ l_b3:(w*x*y)^(1/3)$ l_b4:(u*x*y)^(1/3)$ l_b5: (u*v*y)^(1/3)$ /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ l_a - l_b1*l_b2*l_b3*l_b4*l_b5; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] The difference should be zero! The problem araises from the fact the products are too huge so that the diffenrence consist solely of approximation errors. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Calculate the sine of the numerical value of pi. What should you get? do they match? [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* [wxMaxima: input end ] */ /* Maxima can't load/batch files which end with a comment! */ "Created with wxMaxima"$