demo1 - demo1.nb 1 Mathematica Demo #1 à Arithmetic...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: demo1.nb 1 Mathematica Demo #1 à Arithmetic Shift-Enter --> Calculate (inputs any calculation you would like performed) "+" --> Addition "-" --> Subraction "*" or " " --> Multiplication "/" --> Division "^" --> Exponent Ÿ Examples: 2.3 + 5.63 7.93 2.4 €€€€€€€€€€€€€€€€€€€€ 8.9^ 2 0.0302992 234 24 H3 + 4L ^ 2 - 2 H3 + 1L 41 Order of execution is always by standard convention. Exponents first, followed by multiplication and division, then lastly addition and subtraction. If two operations are of the same priority, parenthetical operations are performed first if applicable, or the operation that comes first sequentially. à Scientific Notation One enters a number in scientific notation in the following way: 2.3 * 10 ^ 70 2.3 ´ 1070 demo1.nb 2 à Exact and Approximate Results Mathematica will generally default to an exact answer; however, this is not always the most desirable format. The "//N" or "N[expr]" switch allows the program to approximate the solution to a fixed number of decimal places. It is specifically defined in the following way: ?N N@exprD gives the numerical value of expr. N@expr, nD attempts to give a result with n-digit precision. Note that ?Function gives the help description of any function or command. Ÿ Examples: 2 ^ 100 1267650600228229401496703205376 N@2 ^ 100D 1.26765 ´ 1030 2 ^ 100 •• N 1.26765 ´ 1030 N@2 ^ 100, 15D 1.26765060022823 ´ 1030 Similarly, this switch will transform rational fractions to decimal form, or a square root from its exact symbolic form to a decimal form. 1 2 €€€€€ + €€€€€ 3 7 13 €€€€€€€€ € 21 1 2 NA €€€€€ + €€€€€ E 3 7 0.6190476190476191 Lastly, note the differences in output depending on how the input is entered. In particular, note the effect of adding a decimal point to change the argument from an integer to a real number. demo1.nb 3 Sqrt@2D •++++ 2 N@Sqrt@2DD 1.41421 Sqrt@2.D 1.41421 à Common Mathematical Functions Sqrt[x] --> square root Exp[x] --> exponential Log[x] --> natural logarithm Log[b,x] --> logarithm to base b Sin[x], Cos[x], Tan[x], Csc[x], Sec[x], Cot[x] --> trigonometric functions (x in radians) ArcSin[x], ArcCos[x], ArcTan[x], ArcCsc[x], ArcSec[x], ArcCot[x] --> inverse trigonometric functions (results in radians) Sinh[x], Cosh[x], Tanh[x], Csch[x], Sech[x], Coth[x] --> hyperbolic functions ArcSinh[x], ArcCosh[x], ArcTanh[x], ArcCsch[x], ArcSech[x], ArcCoth[x] --> inverse hyperbolic functions n! --> factorial Abs[x] --> absolute value Round[x] --> closest integer to x FactorInteger[x] --> prime factors of n Ÿ Examples: Sqrt@65D + •++++++ 65 Sqrt@65.D 8.06226 Log@56.D 4.02535 Log@10, 1353.D 3.1313 demo1.nb 4 Pi SinA €€€€€€€€ E € 2 1 6! 720 FactorInteger@63D 883, 2<, 87, 1<< Note that all Mathematica functions begin with capital letters, and that their arguments are enclosed in square brackets. à Mathematical Constants Pi --> pi (3.14159....) E --> e (2.71828....) Degree --> Pi / 180 (converts degrees to radians) I --> Sqrt[-1] (imaginary number) Infinity --> infinity EulerGamma --> Euler's constant (0.577216....) Ÿ Examples: Pi p N@PiD 3.14159 N@Pi, 40D 3.141592653589793238462643383279502884197 à Complex Numbers As mentioned in the previous section, complex numbers may be denoted by adding the constant I. ?I I represents the imaginary unit Sqrt@-1D. Sqrt@- 4D 2I demo1.nb 5 N@Exp@2 + 9 IDD - 6.73239 + 3.04517 I Ÿ Useful Commands for Complex Numbers: Re[z] --> real part of z Im[z] --> imaginary part of z Conjugate[z] --> complex conjugate of z Abs[z] --> absolute value (magnitude) of z Arg[z] --> argument (phase) of z Ÿ Examples: N@Re@Exp@2 + 9 IDDD - 6.73239 N@Im@Exp@2 + 9 IDDD 3.04517 N@Conjugate@Exp@2 + 9 IDDD - 6.73239 - 3.04517 I N@Abs@Exp@2 + 9 IDDD 7.38906 N@Arg@Exp@2 + 9 IDDD 2.71681 à Referencing Previous Results Oftentimes, it is convenient to build upon previous results in performing calculations. The following tricks let one do so. % --> the last result generated %% --> the next-to-last result generated %%...% (k times) --> the kth previous result %n --> the result on output line Out[n] (careful with this one!!!) demo1.nb 6 ?% %n or Out@nD is a global object that is assigned to be the value produced on the nth output line. % gives the last result generated. %% gives the result before last. %% ... % Hk timesL gives the kth previous result. Ÿ Examples: 77 ^ 2 5929 %+1 5930 3 % + % ^ 2 + %% 35188619 In using the notebook format in Mathematica, you have to be extremely careful using these symbols to reference previous results. This is because "%" references the last output generated, regardless of whether that result appears immediately above your present position in the notebook. Thus, the ability to scroll back in the notebook makes the use of this command a risky endeavor. à Defining Variables Since the previous section points out the dangers of using "%" to reference previous calculations, a better alternative is to define a variable. x = value --> assign a value to the variable x x = y = value --> assign a value to both x and y x = . or Clear[x] --> remove any value assigned to x ?= lhs = rhs evaluates rhs and assigns the result to be the value of lhs. >From then on, lhs is replaced by rhs whenever it appears. 8l1, l2, ... < = 8r1, r2, ... < evaluates the ri, and assigns the results to be the values of the corresponding li. ? =. lhs =. removes any rules defined for lhs. Ÿ Examples: x=5 5 demo1.nb 7 x^2 25 x=7+4 11 x =. x x The value assigned to a variable will remain for your entire Mathematica session unless it is explicitly cleared. Thus, to avoid confusion, it is wise to remove variables once you are finished using them. The only restriction in naming variables is that they cannot start with numbers. They can have numbers in their definition, but the first character must be a letter. It is also recommended that the first character not be a capital letter, to avoid confusion with existing Mathematica functions. Ÿ Examples: x y --> implies x times y xy --> implies the variable named xy 5x --> implies 5 times x (since variables cannot begin with a number) x^2y --> implies (x^2)y, not x^(2y) à Making Lists of Objects Sometimes it is convenient to gather together several objects and treat them as a single entity. This can be done with lists, which are formed using curly brackets "{}". ?8 8e1, e2, ... < is a list of elements. Ÿ Examples: x = 83, 5, 1< 83, 5, 1< x^2 + 1 810, 26, 2< demo1.nb 8 There are some commands for manipulating portions of lists: Part[list, i] or list[[i]] --> the ith element of a list Part[list,-i] or list[[-i]] --> the ith element from the end of a list Part[list, {n1, n2, ...}] or list[[{n1, n2,...}]] --> the list of elements at positions n1, n2,... Part[list,i] = value or list[[i]] = value --> reset the ith element of a list First[list] --> the first element in a list Last[list] --> the last element in a list Take[list, n] --> the first n elements in a list Take[list, -n] --> the last n elements in a list Take[list, {m, n}] --> elements m through n (inclusive) in a list Rest[list] --> a list with its first element dropped Drop[list, n] --> a list with its first n elements dropped Drop[list, -n] --> a list with its last n elements dropped Drop[list, {m, n}] --> a list with elements m through n (inclusive) dropped à Sequences of Operations You will typically perform a series of calculations in Mathematica by typing each on a separate line. However, this is not always necessary, as shown below. ?; expr1; expr2; ... evaluates the expri in turn, giving the last one as the result. Ÿ Examples: x = 4; y = 6; z = y + 6 12 The use of a semi-colon has the effect of separating a sequence of calculations and only outputing the result for the final one in this case. The semi-colon can also be used to avoid an output for a single calculation. Ÿ Examples: x = 67 - 5; x 62 demo1.nb 9 x =. à Symbolic Algebraic Computations Mathematica has the ability to take algebraic expressions or equations and manipulate them symbolically. This is demonstrated below: Ÿ Examples: 3x-x+2 2+2x There are also a variety of commands for manipulating these expressions: Expand[expr] --> multiply out products and powers ExpandAll[expr] --> apply Expand everywhere Factor[expr] --> write an expression as a product of minimal factors Together[expr] --> put all terms over a common denominator Apart[expr] --> separate into terms with simple denominators Cancel[expr] --> cancel common factors between numerators and denominators Simplify[expr] --> try to find the simplest form of an expression by applying various standard algebraic transformations Collect[expr, x] --> group together powers of x FactorTerms[expr, x] --> pull out factors that do not depend on x Ÿ Examples: y = Hx ^ 2 + 2 x + 1L Hx - 2L ^ 2 H- 2 + xL2 H1 + 2 x + x2 L z = Expand@yD 4 + 4 x - 3 x2 - 2 x3 + x4 Factor@zD H- 2 + xL2 H1 + xL2 y =.; z =.; Hx - 1L ^ 2 H2 + xL y = €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ H1 + xL Hx - 3L ^ 2 H- 1 + xL2 H2 + xL €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ H- 3 + xL2 H1 + xL demo1.nb 10 z = Expand@yD 2 3x x3 €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ - €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ + €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ H- 3 + xL2 H1 + xL H- 3 + xL2 H1 + xL H- 3 + xL2 H1 + xL z = ExpandAll@yD 2 3x x3 €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ - €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ + €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ € € € 2 + x3 2 + x3 9+3x-5x 9+3x-5x 9 + 3 x - 5 x2 + x3 a = Together@zD 2 - 3 x + x3 €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ € 9 + 3 x - 5 x2 + x3 Apart@aD 5 19 1 1 + €€€€€€€€€€€€€€€€€€€€€€€€€€€ + €€€€€€€€€€€€€€€€€€€€€€€€€€€€€ + €€€€€€€€€€€€€€€€€€€€€€€€€€ € 4 H- 3 + xL 4 H1 + xL H- 3 + xL2 x =.; y =.; z =.; a =.; Here are a couple more expressions: ComplexExpand[expr] --> perform expansions assuming that all variables are real PowerExpand[expr] --> transform (xy)^p into x^p y^p, etc. Ÿ Examples: ComplexExpand@Sin@x + I yDD Cosh@yD Sin@xD + I Cos@xD Sinh@yD PowerExpand@Sqrt@x yDD •++++ •++++ xy There are still other commands for manipulating algebraic expressions: Coefficient[expr, form] --> coefficient of form in expr Exponent[expr, form] --> maximum power of form in expr Numerator[expr] --> numerator of expr Denominator[expr] --> denominator of expr Ÿ Examples: z =.; y =.; x =.; z = Expand@H1 + 3 x + 4 y ^ 2L ^ 2D 1 + 6 x + 9 x2 + 8 y2 + 24 x y2 + 16 y4 demo1.nb 11 Coefficient@z, xD 6 + 24 y2 Exponent@z, yD 4 1+x z = €€€€€€€€€€€€€€€€€€€€€€€€€€ 2 H2 - yL 1+x €€€€€€€€€€€€€€€€€€€€€€€€€€ 2 H2 - yL Denominator@zD 2 H2 - yL à Values for Symbols Often when a symbolic expression is created, one wants to know what the result would be if a particular value were substituted in for the variable. This can be done as follows: ? /. expr •. rules applies a rule or list of rules in an attempt to transform each subpart of an expression expr. ? -> lhs -> rhs represents a rule that transforms lhs to rhs. Ÿ Examples: 1 + 2 x •. x ® 3 7 1 + x + x ^ 2 •. x ® 2 - y 3 + H2 - yL2 - y Hx + yL Hx - yL ^ 2 •. 8x ® 3, y ® 1 - a< H4 - aL H2 + aL2 t = 1 + x^2 1 + x2 t •. x ® 2 5 demo1.nb 12 t •. x ® 5 a 1 + 25 a2 à Symbolic Differentiation ?D D@f, xD gives the partial derivative of f with respect to x. D@f, 8x, n<D gives the nth partial derivative of f with respect to x. D@f, x1, x2, ... D gives a mixed derivative. Ÿ Examples: D@ArcTan@xD, xD 1 €€€€€€€€€€€€€€€€€ 1 + x2 D@x ^ n, 8x, 3<D H- 2 + nL H- 1 + nL n x-3+n à Integration Ÿ Symbolic ? Integrate Integrate@f, xD gives the indefinite integral of f with respect to x. Integrate@f, 8x, xmin, xmax<D gives the definite integral of f with respect to x from xmin to xmax. Integrate@f, 8x, xmin, xmax<, 8y, ymin, ymax<D gives a multiple definite integral of f with respect to x and y. Ÿ Examples: Integrate@x ^ n, xD x1+n €€€€€€€€€€€€€€ € 1+n 2 Exp@- x ^ 2D IntegrateA €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ , xE Sqrt@PiD Erf@xD Integrate@x ^ 2 + y ^ 2, 8x, 0, 1<, 8y, 0, x<D 1 €€€€€ 3 demo1.nb 13 Ÿ Numerical ? NIntegrate NIntegrate@f, 8x, xmin, xmax<D gives a numerical approximation to the integral of f with respect to x from xmin to xmax. Ÿ Examples: Integrate@Sin@Sin@xDD, 8x, 1, 2<D à Sin@Sin@xDD â x 2 1 NIntegrate@Sin@Sin@xDD, 8x, 1, 2<D 0.816449955123312 à Sums and Products Ÿ Symbolic ? Sum Sum@f, 8i, imax<D evaluates the sum of the expressions f as evaluated for each i from 1 to imax. Sum@f, 8i, imin, imax<D starts with i = imin. Sum@f, 8i, imin, imax, di<D uses steps di. Sum@f, 8i, imin, imax<, 8j, jmin, jmax<, ... D evaluates a sum over multiple indices. ? Product Product@f, 8i, imax<D evaluates the product of the expressions f as evaluated for each i from 1 to imax. Product@f, 8i, imin, imax<D starts with i = imin. Product@f, 8i, imin, imax, di<D uses steps di. Product@f, 8i, imin, imax<, 8j, jmin, jmax<, ... D evaluates a product over multiple indices. Ÿ Examples: Sum@x ^ i • i, 8i, 1, 7<D x2 x3 x4 x5 x6 x7 x + €€€€€€€€ + €€€€€€€€ + €€€€€€€€ + €€€€€€€€ + €€€€€€€€ + €€€€€€€€ 2 3 4 5 6 7 Sum@x ^ i • i, 8i, 1, 7, 2<D x3 x5 x7 x + €€€€€€€€ + €€€€€€€€ + €€€€€€€€ 3 5 7 demo1.nb 14 Product@x + i, 8i, 1, 4<D H1 + xL H2 + xL H3 + xL H4 + xL Ÿ Numerical ? NSum NSum@f, 8i, imin, imax<D gives a numerical approximation to the sum of the expressions f as evaluated for each i from imin to imax. NSum@f, 8i, imin, imax, di<D uses a step di in the sum. ? NProduct NProduct@f, 8i, imin, imax<D gives a numerical approximation to the product of the expressions f as evaluated for each i from imin to imax. NProduct@f, 8i, imin, imax, di<D uses a step di in the product. Ÿ Examples: Sum@1 • i ^ 4, 8i, 1, Infinity<D p4 €€€€€€€€ € 90 NSum@1 • i ^ 4, 8i, 1, Infinity<D 1.08232 à Equations Equations are entered in Mathematica using the "==" notation. ? == lhs == rhs returns True if lhs and rhs are identical. Ÿ Examples: 2 + 2 == 4 True 2 + 2 == 5 False x2 + 2 x - 7 == 0 - 7 + 2 x + x2 == 0 demo1.nb 15 à Other Logical Operators There are other logical operators that Mathematica uses: != --> not equal to > --> greater than >= --> greater than or equal to < --> less than <= --> less than or equal to Ÿ Examples: 3<5<6 True à Solving Equations Ÿ Symbolic ? Solve Solve@eqns, varsD attempts to solve an equation or set of equations for the variables vars. Solve@eqns, vars, elimsD attempts to solve the equations for vars, eliminating the variables elims. Ÿ Examples: Solve@x ^ 2 + 2 x - 7 == 0, xD 99x ® - 1 - 2 •++++ •++++ 2 =, 9x ® - 1 + 2 2 == Solve@x ^ 2 + 1 == 0, xD 88x ® - I<, 8x ® I<< Ÿ Numerical ? NSolve NSolve@lhs==rhs, varD gives a list of numerical approximations to the roots of a polynomial equation. demo1.nb 16 Ÿ Examples: Solve@x ^ 5 + x + 1 == 0, xD + 11 •++++++ 1•3 - €€€€€ J €€€€€ I25 - 3 69 MN =, 32 •++++ + 1-I 3 •++++++ 1•3 I25 - 3 69 MN + €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ =, + •++++++ 1•3 3 22•3 I25 - 3 69 M •++++ + 1+I 3 •++++++ 1•3 I25 - 3 69 MN + €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ == + •++++++ 1•3 3 22•3 I25 - 3 69 M y 1 1i 2 98x ® - H- 1L1•3 <, 8x ® H- 1L2•3 <, 9x ® €€€€€ - €€€€€ j €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ z j +z 3 3 k 25 - 3 •++++++ { 69 1 1 1 •++++ 9x ® €€€€€ + €€€€€ I1 + I 3 M J €€€€€ 3 6 2 1 1 1 •++++ 9x ® €€€€€ + €€€€€ I1 - I 3 M J €€€€€ 3 6 2 NSolve@x ^ 5 + x + 1 == 0, xD 1•3 88x ® - 0.754878<, 8x ® - 0.5 - 0.866025 I<, 8x ® - 0.5 + 0.866025 I<, 8x ® 0.877439 - 0.744862 I<, 8x ® 0.877439 + 0.744862 I<< à Solving Differential Equations Ÿ Symbolic ? DSolve DSolve@eqn, y, xD solves a differential equation for the function y, with independent variable x. DSolve@8eqn1, eqn2, ... <, 8y1, y2, ... <, xD solves a list of differential equations. DSolve@eqn, y, 8x1, x2, ... <D solves a partial differential equation. Ÿ Examples: DSolve@y¢ @xD == a y@xD + 1, y@xD, xD 1 99y@xD ® - €€€€€ + Ea x C@1D== a DSolve@8y¢ @xD == a y@xD + 1, y@0D == 0<, y@xD, xD - 1 + Ea x 99y@xD ® €€€€€€€€€€€€€€€€€€€€€€€€ == a Ÿ Numerical ? NDSolve NDSolve@eqns, y, 8x, xmin, xmax<D finds a numerical solution to the ordinary differential equations eqns for the function y with the independent variable x in the range xmin to xmax. NDSolve@eqns, y, 8x, xmin, xmax<, 8t, tmin, tmax<D finds a numerical solution to the partial differential equations eqns. NDSolve@eqns, 8y1, y2, ... <, 8x, xmin, xmax<D finds numerical solutions for the functions yi. demo1.nb 17 ? Plot Plot@f, 8x, xmin, xmax<D generates a plot of f as a function of x from xmin to xmax. Plot@8f1, f2, ... <, 8x, xmin, xmax<D plots several functions fi. ? Evaluate Evaluate@exprD causes expr to be evaluated even if it appears as the argument of a function whose attributes specify that it should be held unevaluated. Ÿ Examples: z = NDSolve@8y¢ @xD == y@xD, y@0D == 1<, y, 8x, 0, 2<D 88y ® InterpolatingFunction@880., 2.<<, <>D<< y@1.5D •. z 84.48171< Plot@Evaluate@y@xD •. zD, 8x, 0, 2<D 7 6 5 4 3 2 1 0.5 1 1.5 2 … Graphics … à Power Series ? Series Series@f, 8x, x0, n<D generates a power series expansion for f about the point x = x0 to order Hx - x0L^n. Series@f, 8x, x0, nx<, 8y, y0, ny<D successively finds series expansions with respect to y, then x. demo1.nb 18 Ÿ Examples: Series@Cos@xD, 8x, 0, 10<D x2 x4 x6 x8 x10 1 - €€€€€€€€ + €€€€€€€€ - €€€€€€€€€€€€ + €€€€€€€€€€€€€€€€€€ - €€€€€€€€€€€€€€€€€€€€€€€€€ + O@xD11 € € 2 24 720 40320 3628800 à Limits ? Limit Limit@expr, x->x0D finds the limiting value of expr when x approaches x0. Ÿ Examples: Sin@xD t = €€€€€€€€€€€€€€€€€€€€€€ x Sin@xD €€€€€€€€€€€€€€€€€€€€€€ x Limit@t, x ® 0D 1 à Functions Functions are defined using the ":=" symbol. To limit confusion, it is also recommended that you use a lower case character for the first letter of a function. ? := lhs := rhs assigns rhs to be the delayed value of lhs. rhs is maintained in an unevaluated form. When lhs appears, it is replaced by rhs, evaluated afresh each time. The argument of the function is typically defined as any character followed by the underline symbol. This basically makes the argument of the function a wild card, allowing one to substitute any number or variable into the function. ?_ _ or Blank@ D is a pattern object that can stand for any Mathematica expression. _h or Blank@hD can stand for any expression with head h. Ÿ Examples: f@x_D := x2 demo1.nb 19 f@a + 1D H1 + aL2 f@4D 16 Clear@fD Hx - xmaxL2 € f@x_, xmax_D := €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ xmax 2 + f@x, 3.5D 2 + 0.285714 H- 3.5 + xL2 ?f Global`f f@x_, xmax_D := Hx - xmaxL ^ 2 • xmax Clear@fD à Basic Plotting ? Plot Plot@f, 8x, xmin, xmax<D generates a plot of f as a function of x from xmin to xmax. Plot@8f1, f2, ... <, 8x, xmin, xmax<D plots several functions fi. Ÿ Examples: Plot@Sin@xD, 8x, 0, 2 Pi<D 1 0.5 1 -0.5 -1 … Graphics … 2 3 4 5 6 demo1.nb 20 Plot@Tan@xD, 8x, - 3, 3<D 40 20 -3 -2 -1 1 2 3 -20 -40 … Graphics … Plot@8Sin@xD, Sin@2 xD, Sin@3 xD<, 8x, 0, 2 Pi<D 1 0.5 1 2 3 4 5 6 -0.5 -1 … Graphics … plt1 = Plot@Sin@xD, 8x, 0, 2 Pi<D ; plt2 = Plot@Sin@2 xD, 8x, 0, 2 Pi<D ; plt3 = Plot@Sin@3 xD, 8x, 0, 2 Pi<D ; demo1.nb 21 1 0.5 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 -0.5 -1 1 0.5 -0.5 -1 1 0.5 -0.5 -1 ? Show Show@graphics, optionsD displays two- and three-dimensional graphics, using the options specified. Show@g1, g2, ... D shows several plots combined. demo1.nb 22 Show@plt1, plt2, plt3D 1 0.5 1 2 3 4 5 6 -0.5 -1 … Graphics … There are sometimes better ways to make plots, depending on the circumstances. Listed below are the various ways plots can be constructed: Plot[f, {x, xmin, xmax}] --> first choose specific numerical values for x, then evaluate f for each value of x. Plot[Evaluate[f], {x, xmin, xmax}] --> first evaluate f, then choose specific numerical values of x. Plot[Evaluate[Table[f, ... ]], {x, xmin, xmax}] --> generate a list of functions, and then plot them. Plot[Evaluate[y[x] /. solution], {x, xmin, xmax}] --> plot a numerical solution to a differential equation obtained from NDSolve. << Graphics`PlotField` ? PlotVectorField PlotVectorField@f, 8x, x0, x1, HxuL<, 8y, y0, y1, HyuL<, HoptionsLD produces a vector field plot of the two-dimensional vector function f. y Cos@xD f@x_, y_D := €€€€€€€€€€€€€€€€€€€€€€€€€€ € 1 + 2 y2 demo1.nb 23 plt1 = PlotVectorField@81, f@x, yD<, 8x, - 3, 3<, 8y, - 1, 2<, Frame -> TrueD 2 1.5 1 0.5 0 -0.5 -1 -3 -2 -1 0 1 … Graphics … à Just for fun! ? ParametricPlot3D ParametricPlot3D@8fx, fy, fz<, 8t, tmin, tmax<D produces a three-dimensional space curve parametrized by a variable t which runs from tmin to tmax. ParametricPlot3D@8fx, fy, fz<, 8t, tmin, tmax<, 8u, umin, umax<D produces a three-dimensional surface parametrized by t and u. ParametricPlot3D@8fx, fy, fz, s<, ... D shades the plot according to the color specification s. ParametricPlot3D@88fx, fy, fz<, 8gx, gy, gz<, ... <, ... D plots several objects together. demo1.nb 24 ParametricPlot3D@8t, u, Sin@t * uD<, 8t, 0, 3<, 8u, 0, 3<D 3 2 1 0 1 0.5 0 -0.5 -1 0 1 2 3 … Graphics3D … ...
View Full Document

Ask a homework question - tutors are online