Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4."— Presentation transcript:

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

2 Course Lecture Schedule WeekDateConceptsProject Due 1 2January 28Introduction to the data analysis 3February 4Excel #1 – General Techniques 4February 11Excel #2 – Plotting Graphs/ChartsQuiz #1 5February 18Holiday 6February 25Excel #3 – Statistical AnalysisQuiz #2 7March 3Excel #4 – Regression Analysis 8March 10Excel #5 – Interactive ProgrammingQuiz #3 9March 17Introduction to Computer Programming - Part - I March 24Spring Recesses 10March 31Introduction to Computer Programming - Part - II(4/4) Project #1 11April 7Programming – #1Quiz #4 12April 14Programming – #2 13April 21Programming – #3Quiz #5 14April 28Programming – #4 15May 5Programming - #5Quiz #6 16May 12Movies / EvaluationsProject #2 FinalMay 19Final Examination (3-6pm COB 116)

3 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.

4 How do you like Scilab so far? Great Tool!

5 Outline 1. Using Scilab Editor 2. Simple Statistical Analysis 3. Reading data files. 5

6 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

7 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.

8 UC Merced 8 Any Questions?

9 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

10 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 = 112 // 1 row x 12 columns -->sum(x) // sum of vector/matrix entries ans = 33.7

11 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)

12 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

13 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] -->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

14 Descriptive Statistical Analysis – cont. What is an standard deviation of Test 4? What is a total score of Person A? 14 -->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.

15 Descriptive Statistical Analysis – cont. What is a histogram of Person C? 15 -->x=[68 53 52; 87 65 100; 99 66 59; 98 92 67] -->histplot(5,x(:,3))

16 UC Merced 16 Any Questions?

17 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)

18 Current and Working directories SCILAB uses a current directory where files are saved by default, for example when using the function diary. To see the current directory use: -->pwd Under 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’) Or 18

19 Click “Change Directory’ in the File menu. Once the browse window pops up, navigate yourself to the directory where your file is. 19

20 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.

21 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.

22 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 name Don’t know the exact number of rows # of columns

23 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.

24 UC Merced 24 Any Questions?

25 Next Lecture Programming in Scialb Programming is the basic skill for implementing numerical analysis. Solving some difference equations 25


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

Similar presentations


Ads by Google