0% found this document useful (1 vote)
252 views21 pages

Exploration With CAS-I.lab1

This document provides instructions for a Scilab lab exploring the computational software Scilab. It discusses installing Scilab, working in the console, arithmetic operations, built-in math functions, defining variables, and creating script files. Script files allow saving and re-running sequences of Scilab commands to conveniently perform calculations and numerical problems.

Uploaded by

Riya Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
252 views21 pages

Exploration With CAS-I.lab1

This document provides instructions for a Scilab lab exploring the computational software Scilab. It discusses installing Scilab, working in the console, arithmetic operations, built-in math functions, defining variables, and creating script files. Script files allow saving and re-running sequences of Scilab commands to conveniently perform calculations and numerical problems.

Uploaded by

Riya Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Exploration with CAS-I

BMA 151
Objective:
• To enhance the numerical computational
skills of prospective engineers using open
source software/ computer algebra system(CAS)

• To plot of graphs of complicated functions .


LAB-1:Starting with Scilab
• Index
1.1 What is SCILAB
1.2. How to Install Scilab
1.3.Working in the console
1.4.Arithmetic Operations with scalars
1.5.Elementary Math Build-in functions
1.6.Defining scalar variables
1.7.Script Files
1.1 What is SCILAB
• It is a software for Numerical computations
2D/3D Plotting.
• It is free and open source software.
• Available for various operating systems(OS)
e.g. Windows, Linux and Mac OS/X
• Its syntax is simple.
• Many numerical problems can be expressed in a
reduced number of code lines, as compared to
similar solutions using traditional languages.
Continued….

• CNES (French Space Satellite Agency)


using Scilab successfully.

• IIT Mumbai: Shifting all computational


labs to Scilab
1.2. How to Install Scilab
• Visit: www.scilab.org.
• Various versions of Scilab available for
different Operating systems
• Download the file as per the operating system
in your computer.
• And run it in your computer.
• An icon of Scilab is created on your desktop.
• Double click on the icon and we are in Scilab
environment: File browser, console, variable
browser and command history.
• I am using scilab-6.0.1 for the windows
platform in my system
1.3.Working in the console
• Console is the main window of Scilab
• Used for executing commands(Instructions)
• Opening other windows
• Running programs written by the user

• The ‘prompt’ : -->


The horizontal inbuilt arrow on console is called
prompt in front of which we write instruction(s) called
command line.
• role of ‘enter key’: We get the output of our
calculations done on console by pressing the enter key.
It is also used to write new command line
• ‘ans=’ as the default variable:
Continued…
• Role of commas ,
We can write Multiple commands on same command line separated by commas ,
--> 2,3,5
ans =
2.
ans =
3.
ans =
5.

• Role of semicolon ;
If a semicolon(;) is typed at the end of a command the output of the command is not
displayed
--> 2;3;5
ans =
5.
• Role of commands: clc and clear
clc is used to clear the console though data will still remain stored in the memory
clear removes data from memory
1.4.Arithmetic Operations with scalars
Operation Scilab Symbol Example
Addition + -->3+4
ans=
7
Subtraction - -->4-2
ans=
2
Multiplication * -->3*4
ans=
12
Division / -->3/4
ans=
0.75
Exponential ^ -->3^4
ans=
81 (means 34=81)
Order of precedence

Precedence Mathematical Operation


First Parenthesis (Brackets)
Second Exponential
Third Multiplication , Division( equal
Precedence)

Fourth Addition ,Subtraction( equal Precedence)


Exercises
Compute:
(i)7+8/2
(ii) (7+8)/2
(iii) ( 4+2X5)/7
(iv) 271/3+ 320.2
(Answrs: (i)11, (ii)7.5, (iii)2, (iv) 5
1.5.Elementary Math Build-in functions
Function Description Scilab Command Example
Square root sqrt(x) -->sqrt(81)
ans=
9
Real nth root of a real nthroot(x,n) -->nthroot(80,5)
number x ans=
2.4022489
Exponential(ex) exp(x) -->exp(5)
ans=
148.41316
Natural log(base e). log(x) -->log(1000)
ln ans=
6.9078
Base 10 logarithm. log10(x) -->log(1000)
log ans=
3.0000
Continued…
Function Description Scilab Command Example

x! factorial(x) -->factorial(5)
ans=
120

 %pi -->%pi/3
ans=
1.0471976
Complex number %i -->2+3*%i
i  1
ans=
2. + 3.i
Sine of angle x (x in radians) sin(x) -->sin(%pi/6)
ans=
0.5
Sine of angle x (x in degrees) sind(x) -->sin(30)
ans=
0.5
Exercises
Compute:
(i) 64  e4

(ii) sin  cos 60 0

6
(iii) 4!+ln2+log100
(iv) (2+3i)(4+5i)
(Answers: (i) 62.59815, (ii)1, (iii) 26.693147,
(iv) -7. + 22.i
--> 27^(1/3)+32^(0.2)
ans =
5.

--> sqrt(64)+exp(4)
ans =
62.59815

--> sin(%pi/6)+cosd(60)
ans =
1.

--> factorial(4)+log(2)+log10(100)
ans =
26.693147

--> (2+3*%i)*(4+5*%i)
ans =
-7. + 22.i
1.6.Defining scalar variables
• A variable is a name made of a letter or a
combination of several letters that is assigned
a numerical value.
• = sign is called the assignment operator. It
assigns a value to a variable.
• x=15 means the number 15 is assigned to the
variable x
• A variable is actually a name of memory
location where the variable’s assignment is
stored .
Exercises
By assigning values 2 and 5 to variables a and b
respectively, compute
(i) c=(a+b)2
(ii) d=4a-3b+lna+ c2
--> a=2;b=5;
--> c=(a+b)^2
c =
49.
--> d=4*a-3*b-log(a)+c^2
d =
2393.3069
1.7.Script Files
• Why we need Script files?
• Using the console to execute a series of
commands is not convenient:
(i)The commands in the console can not be
saved and executed again.
(ii) Every time the enter key is pressed only
the last command is executed, and everything
executed before is unchanged. We can not
edit the previous commands.
1.7.Script Files(Continued…)
• What are Script files?
• A different(better) way of executing commands is first to
create a file with a list of commands(program), save it, and
then run(execute) the file.
• A script file is a sequence of Scilab commands( also called
a program)
• When a script file runs, Scilab executes the commands in
the order they are written just as if they were typed in the
console.
• When a script file has a command that generates an out
put, the output is displayed in the console.
• Using an script file is convenient because it can be edited
and executed many times.
• Script files can be typed and edited in any text editor and
then pasted in to the scilab editor(also called scinotes)
1.7.Script Files(Continued…)
• Creating, saving and executing a Script file
• Scilab script files are created and edited in the editor
window( also called scinotes window)
• To Open the Editor:
Click on the Launch SciNotes icon of the toolbar given
at the top
• Creating script file:
Compute: a=(4+2X5)/7
• To save our work done on editor:
Click on the save as icon of the toolbar given at the
top.
select the folder(or Create a new folder) > name the
file > select save.
1.7.Script Files(Continued…)
• Creating, saving and executing a Script file
(continued…)
• Command line for display of the output of our
computation a done on Editor on console:
disp(a) or disp(a, ‘a=‘)
• Click on the save and execute icon on the tool bar of
the Editor.
• Go to the console and you will see the output
displayed there.
• To Open our SciNotes files:
Click on the open icon given on the tool bar of the
Editor > select the file to be opened > select open
Exercises
• Create, save and execute the script file for
the following problem:
The radius of a circle is 2cm. Find its area.
//script file for area of a circle (comment line. It
is not get executed)
clc
clear
r=2;
A=%pi*r^2;
disp(A,"A=")

You might also like