# Question:Worksheet Exercises

## Question:Worksheet Exercises

This question is related to the Question Why I cannot get results of those instructions?

I am doing exercises from the Book introductory Programming Guide. On two different occassions I get two different results. Can someone explain this behavior by Maple 10. I use May 13, 2005 Build ID 190196 on a PC with Windows XP Professional. I Copy below extracts from the two worksheets.

1.6 Exercises.

1. Assign the integers 12321, 23432, and 34543 to the names a, b, and

c. Use these names to ßnd the sum and diÞerence of each pair of

numbers.

> 1.6    Exercises (1)

a := 12321; b := 23432; c := 34543; A := a + b; B := b + c; C := c + a;

a := 12321

b := 23432

c := 34543

A := 35753

B := 57975

C := 46864

>               ND := c - a; E := c - b; F := b - a;

ND := 22222

E := 11111

F := 11111

2. Write two procedures. The ßrst requires two inputs and ßnds their

sum. The second requires two inputs and ßnds their product. Use

these procedures to add and multiply pairs of numbers. How could

you use these procedures to add and multiply three numbers?

>                    s := proc(x, y)  ...  end;

s := proc(x, y)  ...  end;

>                    p := proc(u, v)  ...  end;

p := proc(u, v)  ...  end;

>                    interface(verboseproc = 2)

>                             s(7, 9)

s(7, 9)

>                             s(2, 3)

s(2, 3)

>                             p(7, 9)

p(7, 9)

>                             evalf(%)

p(7, 9)

>

Learning Maple Procedures.

>                          "Hellow World"

"Hellow World"

>                                 1739

>                            a := ----

>                                 1432

1739

a := ----

1432

>                               1

>                               - a

>                               2

1739

----

2864

>                                 /1  \

>                            evalf|- a|

>                                 \2  /

0.6071927374

>                      d  / 3      2         \

>                     --- \x  + 3 x  + log(x)/

>                      dx

2         1

3 x  + 6 x + -

x

>                         help("versions")

>                        help("interface")

>                     f := proc(x)  ...  end;

f := proc(x)  ...  end;

>                               f(9)

3.

>                               f(7)

2.333333333

> 1.6    Exercises (1)

a := 12321; b := 23432; c := 34543; A := a + b; B := b + c; C := c + a;

a := 12321

b := 23432

c := 34543

A := 35753

B := 57975

C := 46864

>               ND := c - a; E := c - b; F := b - a;

ND := 22222

E := 11111

F := 11111

> 1.6 Exercises (2)

s := proc(x, y)  ...  end;

s := proc(x, y)  ...  end;

>                    p := proc(u, v)  ...  end;

p := proc(u, v)  ...  end;

>                    interface(verboseproc = 2)

>                          help("return")

>                             s(7, 9)

16.

>                          help("debug")

>                             trace(f)

f

>                             p(7, 9)

63.

>                  t := proc(x, y, z)  ...  end;

t := proc(x, y, z)  ...  end;

>                           t(7, 9, 10)

26.

>                  w := proc(x, y, z)  ...  end;

w := proc(x, y, z)  ...  end;

>                           w(7, 9, 10)

630.

>                        "Good, Good, Good"

"Good, Good, Good"

>                          help("array")

>                          help("escape")

2.6 Exercises (1).

>                  a := 5434; b := 6342; % + %%;

a := 5434

b := 6342

11776

>                     c := 92; d := 310; % %%;

c := 92

d := 310

28520

>                              a + b

>                 --------------------------------

>                 VectorCalculus[DotProduct](c, d)

64

---

155

>                                1

>                                -

>                                %

155

---

64

2.6 Exercises (2).

2. Estimate Pi to 10,000 digits.

3. Concatenate three strings "int", "(x^2,", and "x)". Parse the resulting string. Evaluate the parsed string.

5.

Determine a random integer between 40 and 100 using the com-

mand rand(40..100). Concatenate this number with the string, "The

ing string.

6. Assign the expressions x^2 and x*x to the names a and b. Find

the three operands of a and b. Compare the results with those re-

turned by using the dismantle function, that is, dismantle(a) and

dismantle(b). The dismantle function displays the internal data

structure used.

4. The Fibonacci numbers are a sequence of numbers. The ßrst two num-

bers in the sequence are zero (0) and one (1). For n greater than two,

the nth number in the sequence is the sum of the two preceding num-

bers. Assign values to indexed names representing the ßrst, second,

and general Fibonacci numbers.

> ?constants;

>                               /1   \

>                            sin|- Pi|

>                               \2   /

1

>                                  /1   \

>                         evalf|- Pi|

>                                  \2   /

1.5707963267948966192

>                         evalf(Pi)

> n:=4: "p" || (2*n+1);

"p9"

> "p" || (2*m+1);

"p" || (2 m + 1)

> "x" || (1..2) || (1..3);

"x11", "x12", "x13", "x21", "x22", "x23"

> a:=2; a || 4; cat(a,4);

a := 2

a4

24

> a4 := 5; a || 4; cat(a,4);

a4 := 5

5

24

> This is at variance with what is given in the book. Why?

>     s1 := "int"; s2 := "(x^2,"; s3 := "x)"; cat(s1, s2, s3);

s1 := "int"

s2 := "(x^2,"

s3 := "x)"

"int(x^2,x)"

>                           mstring := %

mstring := "int(x^2,x)"

>                          help("parse")

>                          parse(mstring)

/ 2   \

int\x , x/

>                             evalf(%)

3

0.3333333333 x

> 2.6 Exercises (4): Fibonacci Numbers.

Error, missing operator or `;`

> "F:= proc(m:: nonnegint)  local  i, old, new, tem ;   #F(n) denotes the n-th

>

>    Fibonacci number. This procedure gives the first m Fibonacci numbers.

>

>    F(0) := 0; F(1):= 1; old := 0; new := 1; for i  from 2 to m do  tem :=

>

>    new + old; old := new; new := tem; end do; F(new); end proc; "

Error, unable to parse

Fcolon;&equals procApplyFunction(mcolon;&colon nonnegint) local icomma old

comma newcomma tem semi  FApplyFunction(0) colon;&equals 0semi F

ApplyFunction(1)colon;&equals 1semi Typesetting:-mambiguous(

old colon;&equals 0 semi ApplyFunctionnew colon;&equals ,

Typesetting:-merror("unable to parse"))1semi for i  from 2 to m do tem

colon;&equals ApplyFunctionnew  +  ApplyFunctionold semi ApplyFunctionold

colon;&equals ApplyFunctionnew semi ApplyFunctionnew colon;&equals temsemi

end dosemi FApplyFunction(new)semi end procsemi

>                              F(10)

Error, (in F) too many levels of recursion

>                           help("temp")

> ﻿