Exploration With CAS-I.lab1
Exploration With CAS-I.lab1
BMA 151
Objective:
• To enhance the numerical computational
skills of prospective engineers using open
source software/ computer algebra system(CAS)
• 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
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=")