x0 1 215 216 chapter 7 solving calculus problems x0

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: expecting 1 argument, got %1”, nargs elif type(x, ’complex(float )’) then evalf(’erfi ’(x)) elif type(x, ’∞’) then if type(x, ’cx _infinity ’) then undefined + undefined ∗ I elif type(x, ’undefined ’) then NumericTools : −ThrowUndefined (x) elif type(x, ’extended _numeric ’) then x elif type( (x), ’∞’) then ∞ + ∞ ∗ I else CopySign(I, (x)) end if elif type(x, ’undefined ’) then NumericTools : −ThrowUndefined (x, ’preserve ’ = ’axes ’) elif type(x, ‘ ∗ ‘) and member(I, {op(x)}) then erf(−I ∗ x) ∗ I elif type(x, ’complex(numeric )’) and csgn(x) < 0 then − erfi(−x) eliftype(x, ‘ ∗ ‘) and type(op(1, x), ’complex(numeric )’) and csgn(op(1, x)) < 0then − erfi(−x) elif type(x, ‘ + ‘) and traperror(sign(x)) = −1 then − erfi(−x) else ’erfi ’(x) end if end proc The default value of verboseproc is 1. > interface( verboseproc=1 ); The ?interface help page explains the possible settings of verboseproc and the other interface variables. One-Level Evaluation Local variables of a procedure use one-level evaluation. That is, if you assign a local variable, then the result of evaluation is the value most 206 • Chapter 6: Evaluation and Simplification recently assigned directly to that variable. > test:=proc() > local x, y, z; > x := y; > y := z; > z := 5; > x; > end proc: > test(); y Compare this evaluation with the similar interactive example in this section on page 202. Full evaluation within a procedure is rarely necessary and can lead to inefficiency. If you require full evaluation within a procedure, use eval. Commands with Special Evaluation Rules The assigned and evaln Commands The functions assigned and evaln evaluate their arguments only to the level at which they become names. > x := y; x := y > y := z; y := z > evaln(x); x The assigned command checks if a name has a value assigned to it. > assigned( x ); true 6.4 Evaluation Rules • 207 The seq Command The seq command for creating expression sequences does not evaluate its arguments. Therefore, seq can use a variable with an assigned value as a counting variable. > i := 2; i := 2 > seq( i^2, i=1..5 ); 1, 4, 9, 16, 25 > i; 2 Contrast this with the behavior of sum. > sum( i^2, i=1..5 ); Error, (in sum) summation variable previously assigned, second argument evaluates to 2 = 1 .. 5 You can solve this problem by using right single quotes, as shown in the next section. Quotation and Unevaluation The Maple language supports the use of quotes to delay evaluation one level. Surrounding a name in right single quotes (’) prevents Maple from evaluating the name. Hence, right single quotes are referred to as unevaluation quotes. > i := 4; i := 4 > i; 4 > ’i’; 208 • Chapter 6: Evaluation and Simplification i Use this method to avoid the following problem. > i; 4 > sum( i^2, i=1..5 ); Error, (in sum) summation variable previously assigned, second argument evaluates to 4 = 1 .. 5 > sum( ’i^2’, ’i’=1..5 ); 55 > i; 4 Full evaluation of a quoted expression removes one level of quotes. > x := 0; x := 0 > ’’’x’+1’’; ’’x’ + 1’ > %;...
View Full Document

Ask a homework question - tutors are online