math 15 lecture 9 university of california, merced scilab a short introduction – no. 3 today –...

25
Math 15 Lecture 9 Math 15 Lecture 9 University of California, University of California, Merced Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

Upload: spencer-moore

Post on 05-Jan-2016

218 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

Math 15 Lecture 9Math 15 Lecture 9University of California, MercedUniversity of California, Merced

ScilabA Short Introduction – No. 3

Today – Quiz #4

Page 2: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

Course Lecture ScheduleWeek Date Concepts Project Due

1

2 January 28 Introduction to the data analysis

3 February 4 Excel #1 – General Techniques

4 February 11 Excel #2 – Plotting Graphs/Charts Quiz #1

5 February 18 Holiday

6 February 25 Excel #3 – Statistical Analysis Quiz #2

7 March 3 Excel #4 – Regression Analysis

8 March 10 Excel #5 – Interactive Programming Quiz #3

9 March 17 Introduction to Computer Programming - Part - I

March 24 Spring Recesses

10 March 31 Introduction to Computer Programming - Part - II (4/4) Project #1

11 April 7 Programming – #1 Quiz #4

12 April 14 Programming – #2

13 April 21 Programming – #3 Quiz #5

14 April 28 Programming – #4

15 May 5 Programming - #5 Quiz #6

16 May 12 Movies / Evaluations Project #2

Final May 19 Final Examination (3-6pm COB 116)

Page 3: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

Friendly Reminder

New procedure to submit your homework and labs. Don’t the Drop Box for your

submission any longer. Instead, you can submit your work

through the Assignments section of UCMCROP site.

Page 4: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

How do you like Scilab so far?

Great

Tool!

Page 5: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

Outline

1. Using Scilab Editor

2. Simple Statistical Analysis

3. Reading data files.

5

Page 6: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

Scilab Editor The "Editor" menu : launches the SCILAB default editor

SciPad. (Use help scipad for additional information). The SciPad editor can be used to create SCILAB script and function files. As well as to create input data files, or to edit output data files.

6

Page 7: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

Editor – cont.To Execute the program from SciPad.

Click “Load into Scilab” under Execute menu.

Don’t forget to save your program before closing the editor.The file extensions used by scilab are sce and sci.To save a file, click for the menu File and choose Save.

Page 8: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

UC Merced8

Any Questions?

Page 9: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

SCILAB: Descriptive Statistical Analysis

Functions – mean(), median(). Min(), max(), and stdev() are SCILAB functions.

9

-->x=[2,3 3.2 1.5 2.4 3.2 4.2 2.6 1.8 2.2 3.4 4.2];-->mean(x) // Average or Mean ans = 2.8083333

-->median(x) // Median ans = 2.8

-->min(x) // Minimum value ans = 1.5

-->max(x) // Maximum value ans = 4.2

-->stdev(x) // Standard Deviation ans = 0.8805560

Page 10: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

SCILAB: Descriptive Statistical Analysis

Other useful function: length(), size(), and sum()

10

-->x=[2,3 3.2 1.5 2.4 3.2 4.2 2.6 1.8 2.2 3.4 4.2];

-->length(x) //length of object (number of data points) ans = 12. -->size(x) // size of objects ans = 1 12 // 1 row x 12 columns

-->sum(x) // sum of vector/matrix entries ans = 33.7

Page 11: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

Descriptive Statistical Analysis – cont.

Once you have a set of data, it is easy to create the histogram by using histplot() function.histplot(n,data) // n - # of bins and data is a

vector.

11

-->x=[2,3 3.2 1.5 2.4 3.2 4.2 2.6 1.8 2.2 3.4 4.2];-->histplot(5,x)

Page 12: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

Descriptive Statistical Analysis – cont.

What is an average score of Person B?What is an average score of Test 2?What is an standard deviation of Test 4?What is a histogram of Person C?What is a total score of Person A?

You can answer these questions by using Scilab.

12

A B CTest 1 68 53 52Test 2 87 65 100Test 3 99 66 59Test 4 98 92 67

Page 13: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

Descriptive Statistical Analysis – cont.

What is an average score of Person B?

What is an average score of Test 2?

13

-->x=[68 53 52; 87 65 100; 99 66 59; 98 92 67]

A B CTest 1 68 53 52Test 2 87 65 100Test 3 99 66 59Test 4 98 92 67

-->mean(x,’r’) // the rowwise mean.

ans = 88. 69. 69.5

-->mean(x,'c') // the columnwise mean ans = 57.666667 84. 74.666667 85.666667

Page 14: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

Descriptive Statistical Analysis – cont.

What is an standard deviation of Test 4?

What is a total score of Person A?

14

A B CTest 1 68 53 52Test 2 87 65 100Test 3 99 66 59Test 4 98 92 67

-->x=[68 53 52; 87 65 100; 99 66 59; 98 92 67]

-->stdev(x,'c') ans = 8.9628864 17.691806 21.36196 16.441817

-->sum(x,'r') ans =352. 276. 278.

Page 15: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

Descriptive Statistical Analysis – cont.

What is a histogram of Person C?

15

A B CTest 1 68 53 52Test 2 87 65 100Test 3 99 66 59Test 4 98 92 67

-->x=[68 53 52; 87 65 100; 99 66 59; 98 92 67]

-->histplot(5,x(:,3))

Page 16: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

UC Merced16

Any Questions?

Page 17: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

Reading external data files

If there is a file which contains these data, can I use the file to load data into Scilab? (10x10 data)

100 117 20 49 15 45 55 11 90 4933 22 107 11 30 15 45 118 26 76

141 49 34 19 70 89 135 134 91 77124 136 19 130 103 22 16 30 93 19

76 21 12 37 98 66 12 132 49 14198 147 11 103 59 38 54 77 44 84

125 48 95 76 19 116 16 20 104 77112 143 116 99 35 108 34 35 26 19

77 105 136 35 138 12 141 123 49 23144 10 129 35 118 104 84 69 18 12

Page 18: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

Current and Working directoriesSCILAB uses a current directory where files are

saved by default, for example when using the function diary. To see the current directory use:-->pwdUnder a Windows operating system, the default current

directory is typically c:The command pwd stands for Print Working Directory.

At the beginning of a SCILAB session, you can change the current directory to the work directory by using the function chdir:--> chdir(‘c:\Program Files\SCILAB2.5\work’)

Or18

Page 19: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

Click “Change Directory’ in the File menu.Once the browse window pops up, navigate

yourself to the directory where your file is.

19

Page 20: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

Reading external data files – cont.

First, change the directory to the desktop.To read the file by Scilab,

If the previous data are in the file, “data_set.txt”, which is located my desktop.

-->fd = file('open','data_set.txt','unknown');-->data = read(fd,-1,10);-->file('close',fd);-->data data = 100. 117. 20. 49. 15. 45. 55. 11. 90. 49. 33. 22. 107. 11. 30. 15. 45. 118. 26. 76. 141. 49. 34. 19. 70. 89. 135. 134. 91. 77. 124. 136. 19. 130. 103. 22. 16. 30. 93. 19. 76. 21. 12. 37. 98. 66. 12. 132. 49. 141. 98. 147. 11. 103. 59. 38. 54. 77. 44. 84. 125. 48. 95. 76. 19. 116. 16. 20. 104. 77. 112. 143. 116. 99. 35. 108. 34. 35. 26. 19. 77. 105. 136. 35. 138. 12. 141. 123. 49. 23. 144. 10. 129. 35. 118. 104. 84. 69. 18. 12.

Page 21: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

Reading external data files – cont.

-->fd = file('open','data_set.txt','unknown');

•`file' is used to open and close the file and values are recovered by `read'.

-->file('close',fd);Specific file name.

Working with files is a lot like working with notebooks. To use a notebook, you have to open it. When you're done, you have to close it.

With Scilab, it’s easy to read data from plain text files and write to plain text files.

Page 22: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

Reading external data files – cont.

To read the open file, here is a general format:

file-desc : file name m, n : integers (dimensions of the matrix, x). Set m =-1 if you do not know the numbers of rows, so the whole file is read.

i.e:-->data = read(fd,-1,10);

22

X = read(file-desc,m,n)

File nameDon’t know the exact number of rows

# of columns

Page 23: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

Reading external data files – cont.

If you know a file which contains data in the matrix format, you can just simply say:

If the previous data are in the file, “data_set.txt”, which is located my desktop.

-->data = fscanfMat(‘data_set.txt’);-->data data = 100. 117. 20. 49. 15. 45. 55. 11. 90. 49. 33. 22. 107. 11. 30. 15. 45. 118. 26. 76. 141. 49. 34. 19. 70. 89. 135. 134. 91. 77. 124. 136. 19. 130. 103. 22. 16. 30. 93. 19. 76. 21. 12. 37. 98. 66. 12. 132. 49. 141. 98. 147. 11. 103. 59. 38. 54. 77. 44. 84. 125. 48. 95. 76. 19. 116. 16. 20. 104. 77. 112. 143. 116. 99. 35. 108. 34. 35. 26. 19. 77. 105. 136. 35. 138. 12. 141. 123. 49. 23. 144. 10. 129. 35. 118. 104. 84. 69. 18. 12.

Page 24: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

UC Merced24

Any Questions?

Page 25: Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4

Next LectureProgramming in Scialb

Programming is the basic skill for implementing numerical analysis.

Solving some difference equations

ttt

ttt

BAB

BAA

9.01.0

1.09.0

1

1

25