0% found this document useful (0 votes)
93 views13 pages

Global Institute of Engineering and Technology

The document discusses experiments on matrix and vector operations in Scilab. It introduces various functions to create, manipulate and perform operations on matrices and vectors, such as zeros, ones, eye, rand, max, min, sum, prod, sin, cos, exp, log, sqrt, nthroot, sign, cat. Mathematical, logical and element-wise operations are demonstrated on sample matrices and vectors.

Uploaded by

Meer Mustafa Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views13 pages

Global Institute of Engineering and Technology

The document discusses experiments on matrix and vector operations in Scilab. It introduces various functions to create, manipulate and perform operations on matrices and vectors, such as zeros, ones, eye, rand, max, min, sum, prod, sin, cos, exp, log, sqrt, nthroot, sign, cat. Mathematical, logical and element-wise operations are demonstrated on sample matrices and vectors.

Uploaded by

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

CADD and MATLAB

DEPARTMENT OF MECHANICAL ENGINEERING

LAB MANUAL

Academic Year: 2018-19 3rd YEAR II/I-SEMESTER

Programme (UG/PG) : UG

Semester : I

Course Code : ME605PC

Course Title : CADD LAB and MATLAB

Prepared By

Meer Mustafa Ali


(Assistant Professor , Department of Mechanical Engineering)

GLOBAL INSTITUTE OF ENGINEERING


AND TECHNOLOGY
Moinabad, Ranga Reddy District

GLOBAL INSTITUTE OF ENGINEERING AND TECHNOLOGY


CADD and MATLAB

LIST OF EXPERIMENTS & SCHEDULE


Course Title: PROGRAMMING LAB

Exp.
Title
No.

1 Introduction

2 STUDY OF BASIC SCILAB COMMANDS and RELATIONAL & LOGICAL


OPERATIONS
3 MATRIX CONSTRUCTORS AND OPERATIONS

4 CONTROL STRUCTURES (If-Else, If-elseif –else, Select )

5 GRAPHICS - 2D PLOTS

6 Regression And Polynomial Function

7 Multiplication and Inverse of a Matrix

COURSE COORDINATOR HOD

GLOBAL INSTITUTE OF ENGINEERING AND TECHNOLOGY


CADD and MATLAB

STUDY OF BASIC SCILAB COMMANDS


EXP. NO: 1

i. OBJECTIVE: Practicing SCILAB commands to analyze arithmetic, Logical,


Boolean Operations and SCILAB environment with simple exercises to familiarize
Command Window, History, Workspace, Current Directory, Figure window, Edit
window, Shortcuts, Help files.
ii. SOURCE CODE :
Working on general commands on scilab environment

Help – detailed help menu for scilab commands


Who – list all the variables from the variable browser window
Whos - list all the variables with byte size, variable type etc.
Clc – Clears command window
Clear – Removes the variable from memory
Quit – to close the session
Pwd – present working directory
Ls – list the files
Ls -ltr – list the detailed view on the files
Cd - to change the directory
Mkdir – to create a new directory

To work on Special variables / Pre-Defined Variables


%pi – 3.14
Ans
% e = 2.718
%eps – epsilon
%inf – infinity

Basic Scalar & Vector Operations


Creation of Scalar Elements
Y = [1 4 6]  Declares a row vetor
yT = [1; 4; 6]  Declares a Column vector
Creation of Vector Elements
Y = [1 4 6; 2 7 3; 4 1 1]
 Creates a 3*3 matrix

To determine the size / order of the vectors.


Size(y)

To change the elements in the given vector


vector(i,j) = value

GLOBAL INSTITUTE OF ENGINEERING AND TECHNOLOGY


CADD and MATLAB

Performing element by element operations using dot operator

.*, ./, .^,


Linspace[a,b,N]  Vector can be created by evenly spaced points. From a to
b the vector is created by ‘N’ evenly spaced points
Eg: linspace[0,1,5]  0 0.25 0.5 0.75 1
Transpose of a matrix – y’
ans =

1. 2. 4.
4. 7. 1.
6. 3. 1.

LOGICAL OPERATORS:
a=0;b=10;
if a and b
disp("Condition is true");
else
disp("Condition is false");
end
if a or b
disp("Condition is true");
end
if (~a)
disp("Condition is true");
end

exec('C:\Users\admin\Documents\relational.sce', -1)

Condition is false

Condition is true

Boolean Matrices
Boolean constants are %t and %f. They can be used in Boolean matrices. The syntax is the
same as for ordinary matrices i.e. they can be concatenated, transposed, etc... Operations symbols
used with Boolean matrices or used to create Boolean matrices are == and ˜.

GLOBAL INSTITUTE OF ENGINEERING AND TECHNOLOGY


CADD and MATLAB

If B is a matrix of Booleans or(B) and and(B) perform the logical or

and and. For example, typing


%t
produces,
%t = T

Similarly,
[ 3,3] == [3,4]

This produces
and
ans =
! TF!

s = 1:6 ; s(s>3)

will display,
ans =
! 4. 5. 6. !

Similarly,
A = [%t %f %t %f], B = [%f %t %f %t]

produces,
A=
and
! TF T F ! B=
! FTFT!

A|B // logical OR
ans =

! TTTT!

A&B // logical AND


ans =

! FFFF!

RESULT

Study of basic SCI Lab commands on arithmetic, Logical,Boolean Operations are worked and
executed

GLOBAL INSTITUTE OF ENGINEERING AND TECHNOLOGY


CADD and MATLAB

MATRIX AND VECTOR OPERATIONS

EXP. NO: 2

i. OBJECTIVE: To study on basic Matrix and vector Construction and Operations.


ii. SOURCE CODE :

Zeros(m,n) – creates m rows with n cols


zeros(3,2)
ans =
0. 0.
0. 0.
0. 0.
Eye(m,n) – creates identity matrix
eye(2,3)
ans =
1. 0. 0.
0. 1. 0.
Ones(m,n) – creates matrix with all 1’s for all m rows and n cols
ones(2,2)
ans =
1. 1.
1. 1.
rand(m,n) – creates matrix with random numbers
rand(4,4)
ans =
0.2113249 0.6653811 0.8782165 0.7263507
0.7560439 0.6283918 0.0683740 0.1985144
0.0002211 0.8497452 0.5608486 0.5442573
0.3303271 0.6857310 0.6623569 0.2320748

Max(z) -- returns the largest element in a vector.


Y =
1. 4. 6.

GLOBAL INSTITUTE OF ENGINEERING AND TECHNOLOGY


CADD and MATLAB

2. 7. 3.
4. 1. 1.
max(Y)
ans =
7.

Min(z) - returns the smallest element in a vector.


min(Y)
ans =
1.

Sum(z) – returns the sum of elements in a vector


sum(Y)
ans =
29.

prod(z) – returns the product of all elements in a vector.


prod(Y)
ans =
4032.

Mathematical operations
Sin(z) – Retrieve the sine value for the given matrix / vector

sin(Y)
ans =

0.8414710 - 0.7568025 - 0.2794155


0.9092974 0.6569866 0.1411200
- 0.7568025 0.8414710 0.8414710

Similar operation can be obtained for Cos, tan, sec, csc, cot. The hyperbolic for sine, cosine
etc can be retrieved using sinh, cosh etc.

GLOBAL INSTITUTE OF ENGINEERING AND TECHNOLOGY


CADD and MATLAB

Inverse of cosine, sine can be obtained using the acos, asin etc

Exp(z) – Returns the exponential, element wise


exp(Y)
ans =

2.7182818 54.59815 403.42879


7.3890561 1096.6332 20.085537
54.59815 2.7182818 2.7182818

Log10(z) and log(z) provides the base 10 & natural logarithm for the given vector and matix
log(Y)
ans =
0. 1.3862944 1.7917595
0.6931472 1.9459101 1.0986123
1.3862944 0. 0.
Sqrt(z) provides the square root for the matrix elements.
sqrt(Y)
ans =
1. 2. 2.4494897
1.4142136 2.6457513 1.7320508
2. 1. 1.

Performing addition, subtraction, multiplication and division for array vectors or matrix
elements

Floating Point operations


Working on floating point operations like ceil, floor, fix, round for both vectors and matrices

nthroot(x,n) -- Is the real vector/matrix of the nth root of the x elements

nthroot(Y,4)

ans =

1. 1.4142136 1.5650846

GLOBAL INSTITUTE OF ENGINEERING AND TECHNOLOGY


CADD and MATLAB

1.1892071 1.6265766 1.316074

1.4142136 1. 1.

Sign(z) -- returns the matrix made of the signs of z(i,j)

sign(Y)

ans = 1. 1. 1.

1. 1. 1.

1. 1. 1.

Modulo(n,m) – computes n\m and gives the remained.

pmodulo(n,m) – positive arithmetic remainder modulo .

Cat -- Concatenate several arrays

Cat(1,y,z) – concatenates the array / vector ‘y’ with ‘z’ row wise

Y = 1. 4. 6.

2. 7. 3.

4. 1. 1.

Z =

9. 8. 7.

5. 6. 4.

3. 2. 1.

cat(1,Y,Z)

ans =

1. 4. 6.

2. 7. 3.

4. 1. 1.

GLOBAL INSTITUTE OF ENGINEERING AND TECHNOLOGY


CADD and MATLAB

9. 8. 7.

5. 6. 4.

3. 2. 1.

Cat(2,y,z) – concatenates the array / vector ‘y’ with ‘z’ column wise

Matrix Analysis Commands

It helps in finding determinant, Rank and sum of eigen values


y = [1 -2; -2 0 ]
det(y) = -4
rank(y) = 2
trace(y) = 1 [sum(diag(x))]
spec(y)  will provide the eigen values of matrix
= -1.5615528

2.5615528

RESULT :

Thus the Matrix constructors and operations are successfully executed

GLOBAL INSTITUTE OF ENGINEERING AND TECHNOLOGY


CADD and MATLAB

If-Else statement

EXP. NO: 3
i. OBJECTIVE: To write and execute programs that demonstrate on Control
Structures (If-Else, If-elseif –else, Select) using SCI Notes.

ii. ALGORITHM:

STEP 1: Start the program

STEP 2: Get the input from user using input() method.

STEP 3: pmodulo()_gives the positive remainder of the number.

STEP 4: pmodulo(number,2) tells if the number is divisible by 2. By which the the given
number odd or even is determined.

STEP 5: Using select statement multiple cases are executed.

STEP 6: The dayNum returns the number for the given system date ie. Sun is considered
1, Mon = 2 , Tue = 2 etc.

STEP 7: The dayString returns the day ie. Mon,Tue etc.

STEP 8: Using dayString, the different cases are dealt and the statements are dealt
accordingly.

STEP 9: A number is taken as input and checked for positive or negative or zero using the
if-elseif – else condition.

iii. SOURCE CODE :

If- Else Program

To find whether a number is an even number or not


a=input("Enter a number:");
if pmodulo(a,2)==0
disp("Number is even");
else
disp("Number is odd");
end

GLOBAL INSTITUTE OF ENGINEERING AND TECHNOLOGY


CADD and MATLAB

SELECT STATEMENTS:
To print on what day we are in a week

[dayNum,dayString]=weekday(datenum());
select dayString
case "Mon" then
disp("Start of work week");
case "Tue" then
disp("Day2");
case "Wed" then
disp("Day3");
case "Thu" then
disp("Day4");
case "Fri" then
disp("Last day of work week");
else
disp("Weekend");
end

If-elseif –else condition:


To determine whether a number is +ve or –ve or zero
number = input("Enter a number:");
if number >0
disp("positive");
elseif number< 0
disp("negative");
else
disp("Zero");
end

iv. SAMPLE INPUTS & OUTPUTS:

If- Else Program

exec('C:\Users\admin\Documents\if.sce', -1)
Enter a number:5

Number is odd

-->exec('C:\Users\admin\Documents\if.sce', -1)
Enter a number:6

Number is even

GLOBAL INSTITUTE OF ENGINEERING AND TECHNOLOGY


CADD and MATLAB

SELECT STATEMENTS:
--

>exec('C:\Users\admin\Documents\select.s

ce', -1) Start of work week

If-elseif –else condition:

exec('C:\Users\admin\Documents\nestedif.sce', -1)
Enter a

number:4

positive

--
>exec('C:\Users\admin\Documents\nestedif.sc
e', -1) Enter a number:0

Zero

-->exec('C:\Users\admin\Documents\nestedif.sce', -1)
Enter a

number:-7

negative

RESULT :

The programs are executed using if-else, select, if-else if-else statements.

GLOBAL INSTITUTE OF ENGINEERING AND


TECHNOLOGY

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy