




















Estude fácil! Tem muito documento disponível na Docsity
Ganhe pontos ajudando outros esrudantes ou compre um plano Premium
Prepare-se para as provas
Estude fácil! Tem muito documento disponível na Docsity
Prepare-se para as provas com trabalhos de outros alunos como você, aqui na Docsity
Encontra documentos específicos para os exames da tua universidade
Prepare-se com as videoaulas e exercícios resolvidos criados a partir da grade da sua Universidade
Responda perguntas de provas passadas e avalie sua preparação.
Ganhe pontos para baixar
Ganhe pontos ajudando outros esrudantes ou compre um plano Premium
chapter 2 book maxima
Tipologia: Manuais, Projetos, Pesquisas
1 / 28
Esta página não é visível na pré-visualização
Não perca as partes importantes!





















In this Chapter we introduce calculations with real and complex numbers using Maxima. We also introduce the use of functions, conditional statements, and logical particles. This chapter also includes examples of calculations using units of measurements. Symbolic and floating-point results with real numbers In this section we present simple calculations with real numbers and introduce conversion from symbolic to floating-point results. Symbolic results represent the results that one would obtain by working by hand, and producing simplification of operations with numbers. By default, Maxima produces symbolic results when operating with real (and complex) numbers. To produce floating-point values it is necessary to use function float as illustrated in the examples shown below. Notice that the first example shows a simple fraction of integer numbers, while the second example shows a square root calculation. Fractions involving floating-point numbers produce floating-point results, e.g., Changing the default format Use the menu item Numeric > Toggle numeric output to change the default format of calculations with real numbers. For example, activating this item once, changes the default output format to floating point as illustrated below.
A second application of the menu item Numeric > Toggle numeric output will return the default output format to symbolic: In this specific example the output %e-2^ is the symbolic representation of the number e-2 , while 0.1353... is the corresponding floating-point result. Other format changes The Numeric menu includes also the menu items Numeric > To float and Numeric > To bigfloat that can be used to convert a symbolic result into either a simple floating-point format, or to a double-precision floating-point format (referred to as bigfloat in Maxima ). These two menu items are equivalent to the functions float and bfloat , respectively. When applying any of these two menu items, the result refers to the last result available (i.e., to % ). The following two examples show the application of To float and To bigfloat to the number e-. Notice that the last result is in power-of-ten format with b indicating the power of ten. While the output shown uses the default number of digits (16), the value is stored in a double-precision location. Power-of-ten format To enter power-of-ten floating-point values use e to indicate the power of ten, some examples are shown below:
Calculations with real numbers In this sections we present calculations with real numbers involving not only simple arithmetic operations (+, -, *, /, ^), but also square roots ( sqrt ), other roots, absolute values ( abs ), trigonometric functions and their inverses ( sin, cos, asin, acos , etc.), hyperbolic functions and their inverses ( sinh, cosh, asinh, acosh , etc.), exponential ( exp ), natural logarithms ( log – note: not ln), ceiling , floor , fix , and float. By default symbolic results will be provided. Use function float to obtain floating-point results. Please notice that the arguments of trigonometric functions are in radians, the natural angular unit. To convert from degrees to radians use the factor %pi/180. Try some of the following examples (see the results in your own Maxima installation): 2+(1/(2+1/(2+1/2))); 4./3.+3./4.+1./6.; sqrt(1+(3/2)^3); abs(-2.5+1/2.5); sin(%pi/3+cos(%pi/3)); sqrt(exp(-2)+log(abs(-2+1/2))); ceiling(3.25); floor(3.25); fix(3.25); 3.25-fix(3.25); sinh(2.5); Evaluation of formulas Evaluation of formulas is a common application of real number calculations. I suggest using a three-step approach:
Example 2.2: Note: in this last example, kill(all) was used to clear all existing values. Also, the intermediate equation A2:float(%pi*D2^2/4) is calculated before calculating the value of Q. Defining functions To define a function write the function name and arguments, e.g., f(x) , g(y) , h(x,y) , followed by := and by the function definition. Evaluation of the functions is performed by replacing the unknowns with variable names or numerical values. Defining a function as a sequence of expressions Suppose that you want to define a function given by the following expression: f x =
x 2 4
x^3 3x x 2 4 x 3 3x 2
The function definition is now: In this case, evaluation of the function with algebraic arguments will produce a fully expanded expression, e.g., Defining functions with a block statement Functions that require more than one statements to be defined can use the block statement. The block statement is used if a return statement is to be included. The general form of a block- statement function is as follows: block([
x 1,if 0 ≤ x 2 x 1 2 , if 2 ≤ x 4 0, elsewhere
Using the Multiline Input - To enter the command defining the function we will use the Multiline Input window, available by clicking the multiline icon available at the end of the INPUT line in the wxMaxima window. Clicking this icon produces the following window, in which we enter the definition of function f( x) using an if-then command, and an if-then-else command as shown:
Using vectors - To illustrate the operation of the function we will generate a vector of data by evaluating the function at points x = -2, 0, 1, 2, 3, 4, and 5 , i.e., The if-then and if-then-else constructs – In the definition of function f(x) shown above, we used both an if-then and an if-then-else constructs. The if-then construct has the general form: if
The numbers at the lower left corner are the coordinates of a point in the graph. Thus, the resulting gnuplot graphs in Maxima are interactive in the sense that you can place the cursor anywhere in the plot and get the coordinates of that particular point. As mentioned earlier, the graph can be exported to a drawing (or graphics manipulation) software for editing. The following is an edited version of this plot: The following example shows a case where the user controls not only the range of values of x , but also those of y. Make sure to click off the gnuplot graph window before entering a new command in the wxMaxima INPUT line. In this example we plot the function: The graph to the left was generated using: Because the function evaluates to ±∞ at x = -1 , the range of values of y is extremely large, and the variation of the function near y = 0 is not clearly defined. To produce a more detailed graph, use the command:
The following example shows a bi-variate function plotted using function plot3d : The graph is shown below: Additional information on the use of graphics functions in Maxima will be presented on a subsequent chapter on graphics. Calculations using units Operations with units in Maxima requires us to load the unit package. A package in Maxima is a collection of functions related to the package's theme. To see a list of the packages available in Maxima , launch the Maxima Manual by using the menu item Help > Maxima help , and click on the Contents tab. Then, scroll down until you pass all the chapters that start with an upper-case letter. The Maxima packages correspond to those chapters that start with a lower-case letter, as listed below:
The S.I. defines seven basic units corresponding to the following base quantities: ● length meter (m) ● mass kilogram (kg) ● time second (s) ● electric current ampere (A) ● thermodynamic pressure kelvin (K) ● amount of substance mole (mol) ● luminous intensity candela (cd) Combinations of these units produce S.I. derived units such as area (m^2 ), velocity (m/s), and so on [see Table 2 in the NIST SI web page]. Some of these derived quantities have special names and symbols, e.g., [see Table 3 in the NIST SI web page]: ● force newton (N) ● pressure, stress pascal (Pa) ● energy, work, quantity of heat joule (J) ● power watt (W) ● electric charge coulomb (C) ● electric potential difference volt (V) ● capacitance farad (F) ● electric resistance ohm (Ω) ● magnetic flux tesla (T) ● inductance henry (H) ● luminous flux lumen (lm) ● illuminance lux (lx) The S.I. in Maxima Using the unit package in Maxima we can check the reduction of these derived units to its basic units. Compare the results of the following derived units as shown in Maxima with those in Table 3 in the NIST SI web page. To save space, we will create a vector of derived units and check their expressions in terms of the basic units:
We can attach units to values and operate with them as illustrated by this simple example in which we calculate the force required to accelerate a mass of 3 kg to a constant value of 1.5 m/s^2 : Use of function convert Notice that the result will be given in terms of the basic units, thus, instead of showing the result in newtons it is shown in kg ⋅ m/s^2_._ Using function convert it is possible to convert this result to N : Here is another example, in which we calculate the power developed by a particle moving at a velocity of 2.5 m/s under the effect of a force of 4.5 N : The following example shows the calculation of the kinetic energy of a particle of 10 kg of mass moving at 10 m/s : Setting default units Suppose that we are working with units commonly used in fluid mechanics, and that we would like to reduce all unit results to combinations of newtons (N), pascals (Pa), joules (J), and watts (W). In that case, we can force the default units to be:
Y (yotta = 10 24 ) Z (zetta = 10 21 ) E (exa = 10 18 ) P (peta = 10 15 ) T (tera = 10 12 ) G (giga = 10 9 ) M (mega = 10 6 ) k (kilo = 10 3 ) h (hecto = 10 2 ) da (deka = 10 1 ) d (deci = 10
) f (femto = 10
). Notice that the only “strange” characters are %%m for milli and %mu for micro. The other letters are the same as written. Calculations involving S.I. prefixes are shown below: Function convert can be used to convert results to prefixed units (e.g., mm or kPa ), as illustrated below:
The MKS and cgs systems of units Before the S.I. system standardize metric units, there were several “metric” systems used in physics calculations. Two of the best know were the MKS ( meter-kilogram-second ) and the cgs ( centimeter-gram-second ) given in terms of their basic units of length, mass, and time. The MKS system is basically the same as the S.I. system. However, since the units in the cgs system are much smaller in magnitude than the corresponding unit in the MKS system, the cgs system is still used when dealing with small masses and lengths. The conversion of the basic units of the cgs to the MKS system is straightforward: The unit of force in the cgs system is the dyne (abbreviated dyn ), such that 1 dyn = 1 g × 1 cm/s^2 : The unit of work or energy in the cgs system is the erg (I think this is an abbreviation of the word energy ), and it is defined as 1 erg = 1 dyn × 1 cm. However, the Maxima unit package does not contain the erg as one of its units. We can still find a conversion from ergs to joules ( J ) by using: Alternatively, you can add a variable called erg by using: Converting to joules ( J ) we get:
Also, we should point out that electric conductance is the inverse of electric resistance, therefore, the siemens ( S ) and the ohm (Ω) are inverse units, or S ⋅ Ω = 1. Here we use Maxima to check that result: Metric units not available in the unit package This list includes other metric units that are not standard S.I. units, but are commonly used in practice. The list also includes units such as the nautical mile and the know, that, although not metric in origim, are accepted for use in the S.I. For conversion factors, see Table 7 in the NIST S.I. web page] ● length: angstrom (Å), astronomical unit (ua), nautical mile, hectare (ha) ● area: are (a), hectare (ha), barn (b) ● time: hour (h), day (d) ● velocity: knot ● mass: metric ton (t), unified atomic mass unit (u) ● pressure: bar If needed in Maxima , you can define these units as done for the erg, above. The English System (E.S.) of units While the International System (S.I.) has been adopted throughout the world, the English System of units, also known as the British System or the Imperial System, is still very much prevalent in the United States of America 2
. The unit package includes only two of the E.S. units, namely, ● length inch (%in) ● mass slug (slug) The corresponding conversions to S.I. basic units are the following: 2 According to the Wikipedia entry on the International System, as of May 6, 2008, “(t)hree nations have not officially adopted” the S.I. “as their primary or sole system of measurement: Liberia, Myanmar, and the United States.
If you want to do calculations with units of the English System, you could define the following additional unit conversions: ● length foot (ft) = 12 in, mile (mi) = 5280 ft ● force pound (lb) = 1 slug ft/s 2 ● energy British thermal unit (BTU) = 1.0545× 10 3 J ● power horsepower (hp) = 550 lb⋅ft/s Using Maxima : In terms of the basic S.I. units the units defined above are: Converting to related units (e.g., ft to m, mile to km, lb to N, etc.): The fractions shown above, written in floating-point format, are: Functions unitinfo and addunit The unit package is still in development, therefore, it still has some functions that are not yet (May, 2008) implemented such as: ● unitinfo provides definition for a specific unit ● addunits allows user to add other units.html