Presentation is loading. Please wait.

Presentation is loading. Please wait.

MAT 4830 Mathematical Modeling Section 1.2 Simple Programming

Similar presentations


Presentation on theme: "MAT 4830 Mathematical Modeling Section 1.2 Simple Programming"— Presentation transcript:

1 MAT 4830 Mathematical Modeling Section 1.2 Simple Programming http://myhome.spu.edu/lauw

2 Maple Standards Always work in the worksheet mode.

3 Maple Standards Always work in the worksheet mode. Always use the Text mode to type your program (press the Text button).

4 Maple Standards Since your program is in text, it can be copy-and-paste to WORD as text. And your program is editable in WORD.

5 Maple Standards Make sure the font is not too small. Always print in color. Use separate boxes for program and output. Make sure you pay attention to the test cases and the exact format for the input data.

6 Questions 1. What are the 3 components of a computational task?

7 Questions 2. What is the function of “#” ?

8 Questions 3. Name the context of one example.

9 Today… Zeng 1.2 It may be really easy and fast for some of you. Be patient.

10 Zeng 1.2 Introduces the basic elements of Maple programming Open your Maple now (because it takes so long…)

11 Maple Use ONLY worksheet mode. In HW, you need to cut-and-paste your program/results from Maple. Sometimes, strange things happen…

12 Maple I will explain how things work. Understand how computer works help you a long way in programming. Do not type into Maple until I tell you to do so.

13 Example 0 Find the volume of a (circular) cylinder volume=(base area)(height) base area=  (radius 2 )

14 Computational Task 3 Components 1. Data 2. Computational Method 3. Results

15 Example 0

16 Program A program is an implementation of the computational method for the task.

17 Example 0 cylindervolume:=proc(radius,height) # program definition local basearea, volume; # local variables basearea:=Pi*radius^2; # compute the base area volume:=evalf(basearea*height); # compute the volume print(`The volume is`); # output result print(volume); end;

18 Example 0 > cylindervolume(5.5,8.2); The volume is 779.2720578 cylindervolume:=proc(radius,height) # program definition local basearea, volume; # local variables basearea:=Pi*radius^2; # compute the base area volume:=evalf(basearea*height); # compute the volume print(`The volume is`); # output result print(volume); end;

19 Example 0 > r:=5.5: h:=8.2: > cylindervolume(r,h); The volume is 779.2720578 cylindervolume:=proc(radius,height) # program definition local basearea, volume; # local variables basearea:=Pi*radius^2; # compute the base area volume:=evalf(basearea*height); # compute the volume print(`The volume is`); # output result print(volume); end;

20 Good Practices Be sure to use Indentations Empty lines A lot of meaningful comments

21 Example 1 The future value of an annuity: Suppose you make a periodic deposit $R to an account that pays interest rate i per period, for n periods, then the future value $S of the account after n periods will be

22 Example 1 Write a program to calculate the worth of a retirement plan at the end of the term if the plan pays an annual rate A, requires monthly deposit $R, for y years. Then use the program to calculate the future value if the monthly deposit is $300, the annual interest rate is 12%, for 30 years.

23 Example 1 Write a program to calculate the worth of a retirement plan at the end of the term if the plan pays an annual rate A, requires monthly deposit $R, for y years. R=300, A=0.12, y=30, S=? (i=A/12, n=y*12)

24 Example 1

25

26

27 A program that compute the two solutions of the general quadratic equation with the quadratic formula. Use the program to solve Example 2

28 A program that compute the two solutions of the general quadratic equation with the quadratic formula. Use the program to solve Example 2

29 Note: Comments are left out to save time and space. In your HW, you need to put in a lot of comments.

30 Example 2

31 What is not working in Zeng… Cannot use underscore as shown in Zeng e.g. cylinder_volume:=proc(radius,height)

32 Homework Download from the web (individual HW**) Read Zeng Section 1.3


Download ppt "MAT 4830 Mathematical Modeling Section 1.2 Simple Programming"

Similar presentations


Ads by Google