30
CS 122 Engineering Computation Lab Lab 2 Dan De Sousa and Tim Cheeseman Department of Computer Science Drexel University April 2009 ©By the author. All rights reserved. Permission is given to CS122 Spring 2009 staff and students to use and reproduce these notes for their own use.

CS 122 Engineering Computation Lab Lab 2 Dan De Sousa and Tim Cheeseman Department of Computer Science Drexel University April 2009 ©By the author. All

Embed Size (px)

Citation preview

CS 122 Engineering Computation Lab Lab 2

Dan De Sousa and Tim CheesemanDepartment of Computer Science

Drexel UniversityApril 2009

©By the author. All rights reserved. Permission is given to CS122 Spring 2009 staff and students to use and reproduce these notes for their own use.

Your class instructor and TA

• Instructor for this section: Office: Email: Telephone:

• Your TAs are:

Announcements

• Direct questions outside of lab to: – bbVista discussion boards, CLC, contact

email section instructor.– Writing to the course coordinator is like writing

to Papadakis – too far removed to get noticed– Writing to cs122 mail list sends to all students

or will be bounced and ignored.

Announcements

• All members of a group should be able to explain the answers the group gets and be able to knowledgably demonstrate how they were gotten.

• Graders reserve the right to give partial credit, or credit only to some when they spot-check.

Class Overview

Lab 2 Part 0 (Repeat of Lab 1, Part 2)• Solving with Inequalities• Animations

Lab 2 Part 1• Code Edit Regions• Strings and Printing• While Loops• Tables

Solving With Inequalities

• Sometimes we solve equations with multiple solutions.

• We want to limit the solution set to certain criteria.– We can use inequalities!

• Example: Quadratic with positive/negative roots

(Repeat of last week)

Solving With Inequalities

• Recall: To solve a system of equations, we give a set of equations to solve.

(Repeat of last week)

Constraining Solutions

(Repeat of last week)

Constraining Solutions

• We use ‘assuming’ when result is piecewise. This cuts the number of possible solutions:

(Repeat of last week)

Animations

• Animations in Maple are just a list of plots.

• Steps for making animation:– Create a list of plots

• Each element represents one frame of animation• Use plots[display]() to display the list in order

(Repeat of last week)

Animations

• Example:

(Repeat of last week)

Code Edit Regions

A region which allows us to edit code in plain text, instead of “pretty print”. There are a few differences:

• All lines must end with colon or semi-colon– Semi-colon - ; - prints the result of the line to the screen– Colon - : - hides the output

• Use CTRL-E or CMD-E to execute to the block

• Show quick DEMO of creating code edit region

Code Edit Regions

Code Edit Regions

Strings and Printing

When writing code, we often want print out what is happening in our code.

• Strings are “strings” of characters surrounded by double-quotes

• Used by print commands to show us output.

• Print commands are like semi-colon, but allow for more complex combinations

Quick Overview of Strings

Printing

• Two types of print functions in Maple (for use today)– print

• Prints out a sequence of information

– printf• Lets us format strings and substitute numbers into

strings

print()

printf()

printf()

While Loops

• While loops let us repeat a sequence of commands or operations

• The loop runs until a condition is met.

Syntax:

while <condition> do<instruction1><instruction 2> …<instruction n>

end do;

While Loops

Tables

• Used in situations where we need to frequently add items to list.

• Main differences from lists:– Table can grow in size– Can use any value as an index

• You must be especially careful with tables because the index can be any type.

Tables

Putting it all together• Given a list of the height, angle, and distance, find the length of the left wire.

• Assume we have wires of size 530 ft. We can cut them shorter but can’t combine them. So we want to check all our tower specifications to see if any guy wires will be too short.

• We’ll use While loops!

Final Comments

• When writing scripts, test your code every few lines

• Use print statements each step of the way to test your code

• Remember to comment your code so it is easier to read

What you should do now

• Connect to class web page: www.cs.drexel.edu/complab

• Start up Maple 12

• Read Lab 2 directions.

• Do the work with your partner(s). Both should try to do the work, but the grader will need to look at only one answer to give you credit for doing the problem.

Finishing up – save files

• Make sure your name/user id/section number/ date,time/instructor name are on the verification sheet.

• Get the verification sheet signed and handed in.• Save worksheet on desktop if you haven’t done so

already. You can call the file “MyLab2CS122”. This will create a file called MyLab2CS122.mw.

• Submit a copy to Blackboard site.• Email a copy to yourself and/or your lab partners as an

attachment so you can look at what you did for review purposes later.

• .mw file should open correctly on any Maple 12 (Mac, Windows, Linux) – file format is portable across system types.

Next week – Take quiz 2!

• Take the second quiz!

• Go to CLC if you need face-to-face help!

• Don’t wait until the last minute!