 2-Putting Your Ideas Together - Maple Help Part 2: Putting Your Ideas Together Introduction Maple Tutorials are designed to help you get started with Maple, learn about the key tools available in Maple, and lead you through a series of problems.   In Part 2: Putting Your Ideas Together, you will learn one of the essential tools for creating polished documents–how to use typeset mathematics in your text. You will use Maple to solve equations symbolically and numerically.  You will learn how Maple distinguishes an equation from an assignment and an expression from a function.   To try this material on your own, start with an empty Maple document. Perform the steps described in the left column of each table below.  The results of the steps are displayed in the right column for reference.   Refer to Help>Quick Reference for basic getting started tips.   Note for non-Windows users: The keystrokes given in this document are for Windows.  There will be differences for other platforms. If you are using a different platform, see Shortcut Keys. Combining Text and Math

By default, when you start typing in a document, you are in Math mode, allowing you to immediately start computations.  In this section we'll show you how to use both text and math in your document.

Steps

Result

Getting an answer to display inline using [Alt][Enter]

In the examples so far, we obtained a result by pressing [Enter].

You can also get Maple to return the result inline by typing [Alt][Enter] (hold down the Alt key, then press Enter).

Example: Type "1+2" then press [Alt][Enter].













$1+2$ = ${3}$









Entering text

To enter text, use [Ctrl][T] or [F5] to switch to Text entry mode.

You can intersperse explanatory text on lines in between your math computations.  You will also want to be able to insert math into a text paragraph, which is covered next.

This is a simple Maple statement:

$1+2$ = ${3}$

Combining text and math

Example:

1. Toggle to Text entry using [F5].  Type "Solve the equation: "

2. Toggle to Math entry using [F5].  Enter the desired equation.

By default, the math you entered in this sentence is nonexecutable math. In the next example, we combine text and math in one line, evaluating and displaying output.

Solve the equation:













Combining text and math, and executing it

Example:

1. On a new line, toggle to Text entry using [F5].  Type "We solve the equation for x"

2. Press [F5] twice to toggle to executable math.  Enter the desired equation.

3. Press [Alt][Enter].

The shortcut key [F5] is a three-way toggle between text, nonexecutable math, and executable math.  When you are in text mode and want to enter math that is

 • Only for display, press [F5] — nonexecutable math.
 • Meant to be executed, press [F5][F5] — executable math.

We solve the equation for x:  = ${-1}{,}{-2}$

Recalculating

Modify some of the terms in the problem, highlight the entire sentence, and press the button to re-execute the computation.

We solve the equation for x: $\mathrm{solve}\left({x}^{2}+8x+8=0,x\right)$ = ${-}{4}{+}{2}{}\sqrt{{2}}{,}{-}{4}{-}{2}{}\sqrt{{2}}$

Note:  Anything you want Maple to evaluate (such as assignment statements) must be entered in Math mode.

You can check what mode you are in by looking at the context bar above your document, which indicates the current entry mode.

In addition, the background color indicates the current entry mode.

 Text mode Nonexecutable math mode Math mode This is text.  You can click Text, Nonexecutable Math, or Math on the context bar to enter that mode: Exercise: The computation from the exercise at the end of Part 1: Talking to Maple has been carried out below. Add in explanatory text around the polynomial example. Change the original polynomial and update the results.



${x}^{2}+x\cdot y+{y}^{2}$$\stackrel{\text{evaluate at point}}{\to }$${100}{+}{10}{}{y}{+}{{y}}^{{2}}$$\stackrel{\text{integrate w.r.t. y}}{\to }$${100}{}{y}{+}{5}{}{{y}}^{{2}}{+}\frac{{1}}{{3}}{}{{y}}^{{3}}$ Solving Equations

Maple can solve equations and inequalities for their unknowns.

Steps

Result

Defining Equations

To represent an equation in Maple, use the = sign for equality.

Example: Solve the equation $a\cdot {x}^{2}+b\cdot x+c=0$ for $x$ using the Context Panel option Solve>Solve for Variable>x.

$a\cdot {x}^{2}+b\cdot x+c=0$$\stackrel{\text{solve for x}}{\to }$$\left[\left[{x}{=}\frac{{1}}{{2}}{}\frac{{-}{b}{+}\sqrt{{{b}}^{{2}}{-}{4}{}{a}{}{c}}}{{a}}\right]{,}\left[{x}{=}{-}\frac{{1}}{{2}}{}\frac{{b}{+}\sqrt{{{b}}^{{2}}{-}{4}{}{a}{}{c}}}{{a}}\right]\right]$

Solving for Exact Solutions

By default, Maple uses symbolic methods to find the exact solution.

Example: Solve the equation $2\cdot {x}^{2}+6\cdot x-3=0$  for $x$ using Solve>Solve in the Context Panel.

$2\cdot {x}^{2}+6\cdot x-3=0$$\stackrel{\text{solve}}{\to }$$\left\{{x}{=}{-}\frac{{3}}{{2}}{+}\frac{{1}}{{2}}{}\sqrt{{15}}\right\}{,}\left\{{x}{=}{-}\frac{{3}}{{2}}{-}\frac{{1}}{{2}}{}\sqrt{{15}}\right\}$



Solving for Numeric Solutions

If you desire a numeric solution, you must specify it directly.

Example: Using the example above, solve the equation using the Context Panel, this time select Solve>Numerically Solve.

$2\cdot {x}^{2}+6\cdot x-3=0$$\stackrel{\text{solve}}{\to }$${-}{3.436491673}{,}{0.4364916731}$

Solving with Maple Commands

Note that the equivalent Maple commands are solve and fsolve (floating-point solve).

To solve a system of equations, enclose them in a list or set.

Tip: Use this notation to include inequalities such as $t>0$ or $t\ne 0$.

$\mathrm{solve}\left(2\cdot {x}^{2}+6\cdot x-3=0,x\right)$

 ${-}\frac{{3}}{{2}}{+}\frac{{1}}{{2}}{}\sqrt{{15}}{,}{-}\frac{{3}}{{2}}{-}\frac{{1}}{{2}}{}\sqrt{{15}}$ (3.1)

$\mathrm{fsolve}\left(2\cdot {x}^{2}+6\cdot x-3,x\right)$

 ${-}{3.436491673}{,}{0.4364916731}$ (3.2)







$\mathrm{solve}\left(\left\{{t}^{2}{y}^{2}=0,t-y=1,t\ne 0\right\}\right)$

 $\left\{{t}{=}{1}{,}{y}{=}{0}\right\}{,}\left\{{t}{=}{1}{,}{y}{=}{0}\right\}$ (3.3)



Assigning Equations to Variables

You can assign equations to names.  Remember to use := (colon equals) for assignments.

Example:  Assign the equation "$y=\mathrm{mx}+b$" to the variable name "eqn".  Then apply the command rhs to your variable name.

You can use the solve command to solve the equation for $x$.











$\mathrm{rhs}\left(\mathrm{eqn}\right)$

 ${m}{}{x}{+}{b}$ (3.4)









$\mathrm{solve}\left(\mathrm{eqn},x\right)$

 ${-}\frac{{b}{-}{y}}{{m}}$ (3.5)



Tip: If you have a formula containing multiple variables, you will find it useful to define it as an equation rather than a simple expression. That way you will be able to use Maple's solve command (which works on equations) to isolate variables. Expressions, Functions, and Procedures

Learn to define Maple expressions and functions.  To implement more complicated functions, define a procedure.

Steps

Result

Expressions

is an expression in $x$ defined to the right. Warning:  $h$ is not a function!

Example: See the example on the right for what happens when you try to evaluate $h\left(0\right)$ as if it were a function.

In fact, you have not defined a function.  You have assigned the expression $\mathrm{sin}\left(x\right)$ to the name $h$.

Example: To find the value of an expression at a given value of $x$,  you need to evaluate the expression at that point. You can do this with
a) the Context Panel,
b) the eval command,

c) or the evaluate symbol found in the Expression palette.





 ${}$ (4.1)

$h\left(0\right)$













$h$ = ${\mathrm{sin}}{}\left({x}\right)$$\stackrel{\text{evaluate at point}}{\to }$${0}$







 ${0}$ (4.2)



$\genfrac{}{}{0}{}{h}{\phantom{x=a}}|\genfrac{}{}{0}{}{\phantom{\mathrm{f\left(x\right)}}}{x=0}$

 ${0}$ (4.3)



Functions$\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}$Mathematical functions in Maple are represented as operators.  The operator notation is represented by an arrow.is a function in defined to the right.

Example:

To define this function, you can use the palettes.  From the Expression palette, choose ${f}:={a}\to {y}$.    Type F, then press [Tab].  Type x.  Press [Tab].  Type x^2.  Press [Enter] to evaluate this line, thus making the function definition.

To find the value of $F$ at a particular value, call the function $F$ with an argument.

Example: Try to evaluate F at 3 and F at y.

Alternate notation: Using natural math notation

Maple also provides a way to define a function using natural mathematical notation.  To do this, you enter an expression of the form "f(y)=expr" and then convert it into a Maple function.

Example:

Define a function $C\left(y\right)=\sqrt{y}$.  To begin, type this equation.  (You can find the nth root symbol in the Expression palette.)  From the Context Panel for the equation, choose Assign Function.

Note:  Using the arrow operator to define a function is strongly recommended.





$F:=x\to {x}^{2}:$









$F≔x\to {x}^{2}$

 ${x}{→}{{x}}^{{2}}$ (4.4)







$F\left(3\right)$

$F\left(y\right)$





$C\left(y\right)=\sqrt{y}$$\stackrel{\text{assign as function}}{\to }$${C}$



$C\left(y\right)$

 ${{y}}^{{1}{/}{3}}$ (4.5)

$C\left(0.04\right)$

 ${0.3419951893}$ (4.6)



Typing the arrow operator

You can type a function definition directly.  To create the arrow,  type the dash key followed by the greater than key: "->".

Example:

Define

 1 Type "g:=theta"
 2 Now, press [Esc] to get symbol completion.  Select the $\mathrm{θ}$ symbol.  Press [Enter].
 3 Type "->sin(3*theta [Esc]"  and select the $\mathrm{θ}$ symbol again.
 4 Finally, type ")" to complete the expression. End the expression with a colon (:). Press [Enter].

Tip: Ending any expression with a colon (:) suppresses the output.





















$g≔\mathrm{θ}\to \mathrm{sin}\left(3\cdot \mathrm{θ}\right):$



$g\left(\frac{\mathrm{π}}{9}\right)$

 $\frac{{1}}{{2}}{}\sqrt{{3}}$ (4.7)



Multi-Parameter Functions

$G$ is a two parameter function defined to the right.

You can evaluate G at specified points.

Example: Try evaluating G at (1,2) and at (1, y).

Note: This can be extended for use with multi-parameter functions.

$\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}G:=\left(a,b\right)\to {a}^{2}-{b}^{3}:$



$G\left(1,2\right)$ = ${-}{7}$

$G\left(1,y\right)$ = ${1}{-}{{y}}^{{3}}$



Procedures

A function is a special form of the more general procedure.

Example:  See the example on the right for a very basic procedure.

Procedures can include conditional statements, iteration, type checking, local variables, error-handling, and other features of standard programming languages.  For an introduction to Maple programming, see the Basic Programming chapter of the User Manual.

Tip: Use [Shift][Enter] to continue a command on the next line.

$\mathrm{procG}≔\mathbf{proc}\left(a,b\right)\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}{a}^{2}+{b}^{2}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathbf{end}\mathbf{proc}:$



$\mathrm{procG}\left(1,2\right)$ = ${5}$





Maple Syntax and 2-D Math

The examples in these tutorials are done using standard 2-D math notation, where fractions and exponents are entered and displayed as they would be written on paper. Some people prefer to enter commands using 1-D Maple syntax, especially when writing procedures.

Several options are available for those who wish to use Maple syntax. The Code Edit Region, which can be embedded directly into a standard Maple document, provides an editor for easy entry of code written in Maple syntax.

For those who wish to do all interactive work in Maple Syntax, use worksheet mode with the input display set to Maple Notation.

$\frac{{x}^{2}}{\sqrt{y}}$

 $\frac{{{x}}^{{2}}}{\sqrt{{y}}}$ (4.8)
 > x^2/sqrt(y);
 $\frac{{{x}}^{{2}}}{\sqrt{{y}}}$ (4.9)
 > See Also