Docsity

Maple Lab 3 for CS 121 Engineering Computation at Drexel University - Prof. Timothy W. Che, Lab Reports of Computer Science

Toggle sidebar
bg1
2/2/09
1
CS 121 Engineering Computation Lab
Lab 3
Department of Computer Science
Drexel University
February 2-6, 2009
©By the author. All rights reserved. Permission is given to CS121 Fall 2008
staff and students to use and reproduce these notes for their own use.
Your class instructor and TA
• Instructor for this section: Tim Cheeseman
Office: UC 147 (CLC)
• Your TAs are:
061 – Cem Sahin, Lloyd Ricks
561 – Pat Lockner
Note that verification sheet requires you to put
down instructor’s name.
Week 3 and 4 retrospective
• Lab 2: fourth week
• Limited Precision Arithmetic
• Data structure, functions
• Quiz 2: fourth week
• Getting stuck on problems during the quizzes?
– Use the Cyber Learning Center (UC147)!
– Use the discussion board for short questions
Lab 3
• Overview
• Part 1 Scripts (ch. 4 readings)!
• Assignments (function)!
• Part 2 User defined functions
• Part 3 Lists, sets and sequences
• Operations
• Random Number generation
• Reading in data from an external file.
Assignments
• Assignments are of the form
name := expression
where a is a variable and n can be an expression
• Name can be a single letter (upper-/lower- case
sensitive), or a combination of a letter followed by letters
and numbers and underscores.
A a a1 expr L eqn1 my_grade largestScore
• Some names are reserved by Maple and cannot be used
as something to assign to:
Pi for I end quit
Demo of Assignments
• p := x^2
x^2
• p
x^2
• p - 1=0
x ^ 2-1 = 0
• unassign(‘p’)
• p
p
• p-1=0
p-1=0
• p does not stand for “x^2” any more.
pf3
pf4

Partial preview of the text

Download Maple Lab 3 for CS 121 Engineering Computation at Drexel University - Prof. Timothy W. Che and more Lab Reports Computer Science in PDF only on Docsity!

CS 121 Engineering Computation Lab

Lab 3

Department of Computer Science Drexel University February 2-6, 2009 ©By the author. All rights reserved. Permission is given to CS121 Fall 2008 staff and students to use and reproduce these notes for their own use.

Your class instructor and TA

  • Instructor for this section: Tim Cheeseman Office: UC 147 (CLC) Email: [email protected]
  • Your TAs are: 061 – Cem Sahin, Lloyd Ricks 561 – Pat Lockner Note that verification sheet requires you to put down instructor’s name.

Week 3 and 4 retrospective

  • Lab 2: fourth week
    • Limited Precision Arithmetic
    • Data structure, functions
  • Quiz 2: fourth week
  • Getting stuck on problems during the quizzes?
    • Use the Cyber Learning Center (UC147)
    • Use the discussion board for short questions

Lab 3

  • Overview
  • Part 1 Scripts (ch. 4 readings)
    • Assignments (function)
  • Part 2 User defined functions
  • Part 3 Lists, sets and sequences
    • Operations
    • Random Number generation
    • Reading in data from an external file.

Assignments

  • Assignments are of the form name := expression where a is a variable and n can be an expression
  • Name can be a single letter (upper-/lower- case sensitive), or a combination of a letter followed by letters and numbers and underscores. A a a1 expr L eqn1 my_grade largestScore
  • Some names are reserved by Maple and cannot be used as something to assign to: Pi for I end quit

Demo of Assignments

  • p := x^ x^
  • p x^
  • p - 1= x ^ 2-1 = 0
  • unassign(‘p’)
  • p p
  • p-1= p-1=
  • p does not stand for “x^2” any more.

Scripts

  • What is a script?
    • A script is a sequence of operations. Usually, the later operations use the results of the earlier ones.
    • Labels or assignments are used to make the references convenient.
  • How are scripts useful?
    • Scripts are useful when you expect to solve a series of similar problems.
    • Reuse: cut, paste, edit, re-execute.

Pointers on Script Use

  • Rather than use the clickable interface, it's better to lay out the operations textually one line at a time.
  • You can create a script using only clickable operations if you don't need to change the operations that are specified by pop-up menu.
  • Use assignments and labels to refer to results of previous steps.
  • Place "editable quantities" as assignments at the beginning of the script, rather than scattering the editing task all over the script ("I forget, what do I need to change?")

Demo of Script Use

  • Demo the sheep problem. Compared to the script given in section 4.5, we’re replacing the clickable operations with the function version of the solve, eval, and plot operations.
  • This solves the problem for sheepEqn :=N = 220/(1+10*.83^t) popSize := 80
  • Copy region
  • Edit sheepEqn := N = 330/(1+10*.79^t); popSize := 85;
  • Re-execute edited region

User Defined Functions

  • Maple users can define new functions
  • That is one of the key features that makes

Maple less like a calculator and more like

a programming language

How to define your own function

  • Through the clickable interface
    • The general form is from the f:=a->y in the Expression palette
  • User-defined function textually
    • function name := input name-> expression involving inputs
  • The ( ....) - > .....defines the function.
  • The function name := gives the function a name

Usage of User Defined Functions

  • Format: function name ( values for inputs )
  • Example: f := (x) -> sqrt(x) + 1 f(9) evaluates to 4 as a result.
  • Example: g := (a, b) -> (a+b)/ g(3.5, 6.5) evaluates to 5 as a result.

Weeks 5 and 6

  • Take Quiz 3 Monday-Friday Week 6
    • October 27-
    • Maple TA server down for maintenance 9-10am and briefly at 3pm each day during the week.
    • Greater penalty if you take the “late version” of quiz. > > > > > >

Demo of RandomTools

Instructors can use the following slides optionally.

Demo of Import Data

Instructors can use the following slides optionally. Demo of Import Data (cont’d)

Demo of Import Data (cont’d) Demo of Import Data (cont’d)

  • Right Click on the Blue Matrix. Click Assign to a name.
  • The name used here is ‘ thelist’
  • Convert the matrix to a list using
    • Mainlist := convert(thelist,list) Perform the required operations on the list