1 / 28

Scilab A “Very” Short Introduction

Scilab A “Very” Short Introduction. Math 15 Lecture 7 University of California, Merced. Project #1 – Due 3pm on April 4 th , 2008. Projects can be performed individually or in groups of three, with following rules: Teams turn in one project report and get the same grade.

micheal
Download Presentation

Scilab A “Very” Short Introduction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ScilabA “Very” Short Introduction Math 15 Lecture 7 University of California, Merced

  2. Project #1 – Due 3pm on April 4th, 2008 • Projects can be performed individually or in groups of three, with following rules: • Teams turn in one project report and get the same grade. • A team consists of at most 3 people—no copying between teams! • Team project report must include a title page, where a team describe each team member’s contribution. • 10% bonus for projects done individually • Individual projects must not be copied from anyone else • No late project will be accepted! Project #1 has been posted at UCMCROP. UC Merced 2

  3. Any Questions? UC Merced

  4. Course Lecture Schedule

  5. Outline • Scilab • Getting Started • Simple Operations with Scilab • Simple Plots with Scilab

  6. What is Scilab? • Scilab is a numerical, programming and graphics environment available for free from the French Government’s INRIA (National Institute for Informatics and Automation Research). • It is similar in operation to MATLAB. • It is available for free from the Scilab website • www.scilab.org.

  7. What is Scilab? • Scilab is a software for numerical mathematics and scientific visualization. • It is capable of interactive calculations as well as automation of computations through programming. • It provides all basic operations on matrices through built-in functions so that the trouble of developing and testing code for basic operations are completely • Scilab can help you understand all intermediate steps in solving even complicated problems, as easily as using a calculator.

  8. What Scilab can do:

  9. www.scilab.org

  10. UCM Computer Labs

  11. Scilab Environment • The user enters Scilab commands at the prompt (-->). • Scilab can be used as a simple calculator to perform numerical calculations. • It also has the ability to define variables and store values in them so that they can be used later.

  12. Simple Calculator -->2+3 ans = 5. -->2/3 ans = .6666667 -->2^3 ans = 8. • Evaluate -->s=0.5 s = 0.5 -->log(s^2-2*s*cos(s*%pi/2)+1) ans = - 0.6108426 -->

  13. Loading a Value Into a Variable --> a = 2 a = 2. -->b = 3. b = 3. -->c = a+b c = 5. assignment -->a = 2 Variable Value 2 is assigned to the variable, a.

  14. Variables in Excel • Cell names, such as B1, D1 etc., are variables in Excel. 3 is assigned to Cell B2. = (B1 – D3*B4)/(A1+B2^3) UC Merced - Math 15

  15. Mathematical Operations • Few examples of operations • Arithmetic Operations • Trigonometric Operations sin(), cos(), tan(), asin(), acos(), atan(), sinh, cosh etc. • Exponential and logarithmic operations log(), log10(), exp() etc.

  16. Examples sqrt(3^5-2)/exp(2) 2.1009686 atan(3)/asin(0.6) 1.9410157

  17. Let’s program! But be careful! --> x = 3 --> y = 3x - 3 --> x = 3 --> y = 3x - 3 Missing Operator error >>> --> x = 3 --> y = 3*x - 3 y = 6. UC Merced

  18. Special Constants • SCILAB has a number of special constants: • %i unit imaginary number • %pi ratio of circumference to diameter • %e the base of the natural logarithms • %inf the infinity • %nan not-a-number • %f boolean constant ’false’ • %t boolean constant ’true’ • Etc.

  19. Examples sqrt(3^5-2)/exp(2*%pi) 0.0289905 - 5.3327279 tan(2*%pi/3)/cos(3/%pi) - (sqrt(5)-1)^4

  20. Comments • Comments in SCILAB begin with a double forward slash (//) • a = 2.5 // redefining a <return>

  21. Creating Arrays • Array • You can think as a variable carries series of data • i.e. x = 1, 2, 3, 4, 5 • How to define arrays in SCILAB. • V = [1, 2, 3, 4,5] • V = 1 2 3 4 5 • V = [1:5] // array runs from 1 to 5 by 1. • V = 1 2 3 4 5 • V = 1:2:10 or [1:2:10] // array runs from 1 to 10 by 2. • V = 1 3 5 7 9 • V = linspace(0,10,5) // array has 5 evenly spaced points between 0 and 10. • V= 0 2.5 5.0 7.5 10

  22. Array Operation • Row array with starting value, increment, ending value • x = -10: 0.1: 10; • Applying a function to the array • y = sin(x*%pi/10); • Plotting the function • plot(x,y)

  23. Working with Arrys • X = [1 2 3] • Y = [2;1;5] • b = 2*x • c = 2*y Row array (vector) Column array (vector) 2 4 6 4 2 10

  24. Working with Arrays –cont. • z = [2 1 0]; • a = x + z • b = x + y • c = x .* z 3 3 3 You will get an error. You cannot add (or subtract) a row vector to a column vector 2 2 0 You can multiply (or divide) the elements of two same-size arrays (vectors) term by term with the array operator .* (or ./)

  25. Creating Simple Plots • Let’s plot with Scilab. • First define q as an array • theta = linspace(0,2*%pi,100); • Create a linearly spaced 100 elements between 0 and 2p. • Then, calculate • y = sin(theta); • Then, plot the graph • plot(theta,y)

  26. More on plotting • Let’s plot the following functions on the same graph. theta = linspace(0,2*%pi,100); x = sin(theta); y = cos(theta); plot(theta,x,theta,y,'--')

  27. Teaching Philosophy “I hear and I forget. I see and I remember. I do and I understand.” No Pain! No Gain! Confucius 500 B.C. UC Merced - Math 15

  28. Next Lecture • By using Scilab, we can effortlessly solve systems of equations, such as

More Related