math 15 lecture 7 university of california, merced scilab a “very” short introduction

Click here to load reader

Upload: denis-dixon

Post on 29-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Scilab A Short Introduction

Math 15 Lecture 7University of California, MercedScilabA Very Short Introduction1Project #1 Due 3pm on April 4th, 2008UC Merced2Projects 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 peopleno copying between teams!Team project report must include a title page, where a team describe each team members contribution.10% bonus for projects done individuallyIndividual projects must not be copied from anyone elseNo late project will be accepted!Project #1 has been posted at UCMCROP.22UC Merced3Any Questions?

Course Lecture ScheduleWeekDateConceptsProject Due12January 28Introduction to the data analysis3February 4Excel #1 General Techniques4February 11Excel #2 Plotting Graphs/ChartsQuiz #15February 18Holiday6February 25Excel #3 Statistical AnalysisQuiz #27March 3Excel #4 Regression Analysis8March 10Excel #5 Interactive ProgrammingQuiz #39March 17Introduction to Computer Programming - Part - IMarch 24Spring Recesses 10March 31Introduction to Computer Programming - Part - II(4/4) Project #111April 7Programming #1Quiz #412April 14Programming #213April 21Programming #3Quiz #514April 28Programming #415May 5Programming - #5Quiz #616May 12Movies / EvaluationsProject #2FinalMay ???Final Examination

OutlineScilab

Getting Started

Simple Operations with Scilab

Simple Plots with Scilab

5What is Scilab?Scilab is a numerical, programming and graphics environment available for free from the French Governments INRIA (National Institute for Informatics and Automation Research).

It is similar in operation to MATLAB.

It is available for free from the Scilab websitewww.scilab.org.

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.

What Scilab can do:

www.scilab.org

9UCM Computer Labs

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.Simple Calculator-->2+3ans =5.

-->2/3ans =.6666667

-->2^3ans =8.Evaluate

-->s=0.5 s =

0.5

-->log(s^2-2*s*cos(s*%pi/2)+1) ans =

- 0.6108426

-->

Loading a Value Into a Variable--> a = 2 a = 2.

-->b = 3.b = 3.

-->c = a+bc = 5.--> a = 2 VariableassignmentValue 2 is assigned to the variable, a.Variables in ExcelUC Merced - Math 1514Cell names, such as B1, D1 etc., are variables in Excel.= (B1 D3*B4)/(A1+B2^3)

3 is assigned to Cell B2.Mathematical OperationsFew examples of operationsArithmetic Operations

Trigonometric Operationssin(), cos(), tan(), asin(), acos(), atan(), sinh, cosh etc.

Exponential and logarithmic operationslog(), log10(), exp() etc.+Addition-Subtraction*Multiplication/Division^Exponentiation15Examples

sqrt(3^5-2)/exp(2)2.1009686

atan(3)/asin(0.6)1.941015716UC Merced17

Lets program! But be careful!

--> x = 3--> y = 3x - 3--> x = 3--> y = 3x - 3Missing Operator error>>> --> x = 3--> y = 3*x - 3 y = 6.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 trueEtc.18Examples

0.0289905

sqrt(3^5-2)/exp(2*%pi)tan(2*%pi/3)/cos(3/%pi) - (sqrt(5)-1)^4 - 5.332727919CommentsComments in SCILAB begin with a double forward slash (//)a = 2.5 // redefining a

20Creating ArraysArrayYou can think as a variable carries series of datai.e. x = 1, 2, 3, 4, 5How to define arrays in SCILAB.V = [1, 2, 3, 4,5]V = 12345V = [1:5] // array runs from 1 to 5 by 1.V = 12345V = 1:2:10 or [1:2:10] // array runs from 1 to 10 by 2.V = 13579V = linspace(0,10,5) // array has 5 evenly spaced points between 0 and 10.V= 0 2.5 5.0 7.5 1021Array OperationRow array with starting value, increment, ending valuex = -10: 0.1: 10;

Applying a function to the arrayy = sin(x*%pi/10);

Plotting the functionplot(x,y)22Working with ArrysX = [1 2 3]

Y = [2;1;5]

b = 2*x

c = 2*yRow array (vector)Column array (vector)2 4 6421023Working with Arrays cont.z = [2 1 0];a = x + z

b = x + y

c = x .* z

3 3 3You will get an error. You cannot add (or subtract) a row vector to a column vectorYou can multiply (or divide) the elements of two same-size arrays (vectors) term by term with the array operator .* (or ./)2 2 024Creating Simple PlotsLets 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 graphplot(theta,y)

More on plottingLets 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,'--')26Teaching PhilosophyUC Merced - Math 1527 I hear and I forget.I see and I remember.I do and I understand.

Confucius 500 B.C.No Pain! No Gain!

27The point of this slide is to use age-old wisdom to streamline the learning process.The end-goal of teaching is not teaching, but learning.

Notes on Confucius:

Far from trying to build a systematic theory of life and society, Confucius wanted his disciples to think deeply for themselves and relentlessly study the outside world, mostly through the old scriptures and by relating past political events (like the Annals) or past feelings of common people (like the Book of Odes). "By three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest."

The Golden Rule by Confucius and others:"What you do not wish upon yourself, extend not to others." - Confucius (ca. 551479 BCE) "Love your neighbor as yourself" - Moses (ca. 1525-1405 BCE) in the Torah, Leviticus 19:18 "What is hateful to you, do not to your fellow man." - Hillel (ca. 50 BCE-10 CE) "Do unto others as you would have them do unto you." - Jesus (ca. 5 BCE33 CE) in the Gospels,Luke 6:31;Luke 10:27 (affirming of Moses);Matthew 7:12; "Hurt no one so that no one may hurt you" Muhammad (c. 571 632 CE) in The Farewell Sermon.

Next LectureBy using Scilab, we can effortlessly solve systems of equations, such as

Sheet1ABCD1245523363538434

=D2+D3

Sheet2

Sheet3