SlideShare a Scribd company logo
1 of 6
Download to read offline
CSE222: Basic Simulation lab Functions (MatLab)
Module 1: Creating a One-Dimensional Array (Row / Column Vector) Exercise – Creating a vector of even
whole numbers between 31 and 75; Creating a Two-Dimensional Array (Matrix of given size) and (A).
Performing Arithmetic Operations - Addition, Subtraction, Multiplication and Exponentiation. (B). Obtaining
Modified Matrix - Inverse, Transpose, with Appended and Deleted Elements;
Module 2: Performing Matrix Manipulations - Concatenating, Indexing, Sorting, Shifting, Reshaping, Resizing
and Flipping about a Vertical Axis/Horizontal Axis; Creating Arrays X & Y of given size (1 x N) and Performing
(A) Relational Operations - >, <, ==, <=, >=, ~=
(B) Logical Operations - ~, &, |, XOR
Functions:
1. Concatenation
C = [A B] horizontally concatenates matrices A and B
C = [A; B] vertically concatenates matrices A and B
For building a matrix horizontally, each component matrix must have the same number
of rows. When building vertically, each component must have the same number of columns.
C = cat(dim, A, B) concatenates the arrays A and B along array dimension dim.
C = cat(dim, A1, A2, A3, A4, ...) concatenates all the input arrays (A1, A2, A3, A4, and so on)
along array dimension dim.
C = horzcat(A1, A2, ...) horizontally concatenates matrices A1, A2, and so on
C = vertcat(A1, A2, ...) vertically concatenates matrices A1, A2, and so on
2. Indexing
A(m, :) give the all values of mth
row
A(:, n) give the all values of nth
column
3. Sorting
sort(matrix, dimension) Dimension argument 1 sorts matrix columns. Dimension argument 2 sorts
matrix rows.
B = sort(A) sorts the elements along different dimensions of an array, and arranges those
elements in ascending order.
B = sort(A, dim) sorts the elements along the dimension of A specified by a scalar dim.
B = sort(...,mode) sorts the elements in the specified direction, depending on the value of
mode.
'ascend' Ascending order (default)
'descend' Descending order
4. Shifting
B = circshift(A, shiftsize) circularly shifts the values in the array, A, by shiftsize elements
5. Reshaping and Resizing
B = reshape(A,m,n) returns the m-by-n matrix B whose elements are taken column-wise from
A. An error results if A does not have m*n elements.
B = reshape(A,m,n,p,...) or B= reshape(A,[m n p ...]) returns an n-dimensional array with the
same elements as A but reshaped to have the size m-by-n-by-p-by-.... The product of the specified
dimensions, m*n*p*..., must be the same as prod(size(A)).
B = rot90(A) rotates matrix A counterclockwise by 90 degrees.
B = rot90(A,k) rotates matrix A counterclockwise by k*90 degrees, where k is an integer.
6. Flipping
B = fliplr(A) returns A with columns flipped in the left-right direction, that is, about a vertical
axis.
B = flipud(A) returns A with rows flipped in the up-down direction, that is, about a horizontal
axis.
B = flipdim(A,dim) returns A with dimension dim flipped. When the value of dim is 1, the
array is flipped row-wise down. When dim is 2, the array is flipped columnwise left to right.
flipdim(A,1) is the same as flipud(A), and flipdim(A,2) is the same as fliplr(A).
7. Relational Operations
A < B A > B A <= B A >= B A == B A ~= B
The relational operators are <, >, <=, >=, ==, and ~=. Relational operators perform element-
by-element comparisons between two arrays. They return a logical array of the same size, with
elements set to logical 1 (true) where the relation is true, and elements set to logical 0 (false) where
it is not.The operators <, >, <=, and >= use only the real part of their operands for the
comparison. The operators == and ~= test real and imaginary parts.
8. Logical Operations
A & B A| B ~A
The symbols &, |, and ~ are the logical array operators AND, OR, and NOT. These operators
are commonly used in conditional statements, such as if and while, to determine whether or not
to execute a particular block of code. Logical operations return a logical array with elements set to
1 (true) or 0 (false), as appropriate.
xor(A,B) represents the logical exclusive disjunction. xor(A,B) is true when either A or B are
true. If both A and B are true or false, xor(A,B) is false.
Module 3: Generating a set of Commands on a given Vector (Example: X = [1 8 3 9 0 1]) to
(A) Add up the values of the elements (Check with sum)
(B) Compute the Running Sum (Check with sum), where Running Sum for element j = the sum of the
elements from 1 to j, inclusive.
(C) Compute the Sine of the given X-values (should be a vector).
Also, Generating a Random Sequence using rand() / randn() functions and plotting them.
Functions:
1. Sum
B = sum(A) returns sums along different dimensions of an array. If A is floating point, that is
double or single, B is accumulated natively, that is in the same class as A, and B has the same class as
A.
If A is not floating point, B is accumulated in double and B has class double.
If A is a vector, sum(A) returns the sum of the elements.
If A is a matrix, sum(A) treats the columns of A as vectors, returning a row vector of the sums of each
column.
If A is a multidimensional array, sum(A) treats the values along the first non-singleton dimension as
vectors, returning an array of row vectors.
B = sum(A,dim) sums along the dimension of A specified by scalar dim. The dim input is an integer
value from 1 to N, where N is the number of dimensions in A. Set dim to 1 to compute the sum of
each column, 2 to sum rows, etc.
B = cumsum(A) returns the cumulative sum along different dimensions of an array.
If A is a vector, cumsum(A) returns a vector containing the cumulative sum of the elements of A.
If A is a matrix, cumsum(A) returns a matrix the same size as A containing the cumulative sums for
each column of A.
If A is a multidimensional array, cumsum(A) works on the first nonsingleton dimension.
B = cumsum(A,dim) returns the cumulative sum of the elements along the dimension of A specified by
scalar dim. For example, cumsum(A,1) works along the first dimension (the columns); cumsum(A,2)
works along the second dimension (the rows).
2. Sine function
Y = sin(X) returns the circular sine of the elements of X. The sin function operates element-
wise on arrays. The function's domains and ranges include complex values. All angles are in radians.
3. rand()
r = rand(n) returns an n-by-n matrix containing pseudorandom values drawn from the
standard uniform distribution on the open interval (0,1).
r = rand(m,n) or r = rand([m,n]) returns an m-by-n matrix.
r = rand(m,n,p,...) or r = rand([m,n,p,...]) returns an m-by-n-by-p-by-... array.
r = rand returns a scalar.
r = rand(size(A)) returns an array the same size as A.
4. randn()
r = randn(n) returns an n-by-n matrix containing pseudorandom values drawn from the
standard normal distribution.
r = randn(m,n) or r = randn([m,n]) returns an m-by-n matrix.
r = randn(m,n,p,...) or r = randn([m,n,p,...]) returns an m-by-n-by-p-by-... array.
r = randn returns a scalar.
r = randn(size(A)) returns an array the same size as A.
5. plot()
plot(Y) plots the columns of Y versus the index of each value when Y is a real number. For
complex Y, plot(Y) is equivalent to plot(real(Y),imag(Y))
Module 4: Evaluating a given expression and rounding it to the nearest integer value using Round,
Floor, Ceil and Fix functions; Also, generating and Plots of (A) Trigonometric Functions - sin(t), cos(t), tan(t),
sec(t), cosec(t) and cot(t) for a given duration β€˜t’. (B) Logarithmic and other Functions – log(A), log10(A), Square root
of A, Real nth
root of A.
Functions:
1. Round
Y = round(X) rounds the elements of X to the nearest integers. Positive elements with a fractional
part of 0.5 round up to the nearest positive integer. Negative elements with a fractional part of -0.5
round down to the nearest negative integer. For complex X, the imaginary and real parts are rounded
independently.
2. Floor
B = floor(A) rounds the elements of A to the nearest integers less than or equal to A. For complex
A, the imaginary and real parts are rounded independently.
3. Ceil
B = ceil(A) rounds the elements of A to the nearest integers greater than or equal to A. For complex
A, the imaginary and real parts are rounded independently.
4. Fix
B = fix(A) rounds the elements of A toward zero, resulting in an array of integers. For complex
A, the imaginary and real parts are rounded independently.
Example:-
a = [-1.9, -0.2, 3.4, 5.6, 7.0, 2.4+3.6i]
a = -1.9000 -0.2000 3.4000 5.6000 7.0000 2.4000 + 3.6000i
>> round(a)
ans = -2.0000 0 3.0000 6.0000 7.0000 2.0000 + 4.0000i
>> floor(a)
ans = -2.0000 -1.0000 3.0000 5.0000 7.0000 2.0000 + 3.0000i
>> ceil(a)
ans = -1.0000 0 4.0000 6.0000 7.0000 3.0000 + 4.0000i
>> fix(a)
ans = -1.0000 0 3.0000 5.0000 7.0000 2.0000 + 3.0000i
5. Square root
B = sqrt(X) returns the square root of each element of the array X. For the elements of X that are
negative or complex, sqrt(X) produces complex results.
6. Real nth
root
y = nthroot(X, n) returns the real nth root of the elements of X. Both X and n must be real and n
must be a scalar. If X has negative entries, n must be an odd integer.
Module 5: Creating a vector X with elements, Xn = (-1)n+1
/(2n-1) and Adding up 100 elements of the
vector, X; And, plotting the functions, x, x3
, ex
and exp(x2
) over the interval 0 < x < 4 (by choosing appropriate
mesh values for x to obtain smooth curves), on (A). A Rectangular Plot (B). A Semi log Plot (C). A log-log Plot
Module 6: Generating a Sinusoidal Signal of a given frequency (say, 100Hz) and Plotting with Graphical
Enhancements - Titling, Labelling, Adding Text, Adding Legends, Adding New Plots to Existing Plot, Printing
Text in Greek Letters, Plotting as Multiple and Subplots; Also, Making Non-Choppy and Smooth Plot of
the functions, f(x) = sin(1/x) for 0.01< x < 0.1 and g(x) = (sin x) /x.
Module 7: Creating a Structure, an Array of Structures and Writing Commands to Access Elements of the
created Structure and Array of Structures; Also, Solving First Order Ordinary Differential Equation using Built-
in Functions; And, Creating an M x N Array of Random Numbers using rand and setting any value that
is < 0.2 to β€˜0’ and any value that is β‰₯ 0.2 to β€˜1’ by moving through the Array, Element by Element.
Functions:
1. s = struct creates a scalar (1-by-1) structure with no fields.
2. s = struct(field,value) creates a structure array with the specified field and values.
Example:
Create a nonscalar structure with one field, f.
field = 'f';
value = {'some text';
[10, 20, 30];
magic(5)};
s = struct(field,value)
s =
3x1 struct array with fields:
f
View the contents each element.
s.f
ans =
some text
ans =
10 20 30
ans =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
When you access a field of a nonscalar structure, such as s.f, MATLAB returns a comma-separated
list. In this case, s.f is equivalent to s(1).f, s(2).f, s(3).f.
3. s = struct(field1,value1,...,fieldN,valueN) creates a structure array
Example
Create a nonscalar structure with several fields.
field1 = 'f1'; value1 = zeros(1,10);
field2 = 'f2'; value2 = {'a', 'b'};
field3 = 'f3'; value3 = {pi, pi.^2};
field4 = 'f4'; value4 = {'fourth'};
s = struct(field1,value1,field2,value2,field3,value3,field4,value4)
s =
1x2 struct array with fields:
f1
f2
f3
f4
The cell arrays for value2 and value3 are 1-by-2, so s is also 1-by-2. Because value1 is a numeric array and not a
cell array, both s(1).f1 and s(2).f1 have the same contents. Similarly, because the cell array for value4 has a single
element, s(1).f4 and s(2).f4 have the same contents.
s(1)
ans =
f1: [0 0 0 0 0 0 0 0 0 0]
f2: 'a'
f3: 3.1416
f4: 'fourth's(2)ans =
f1: [0 0 0 0 0 0 0 0 0 0]
f2: 'b'
f3: 9.8696
f4: 'fourth'
4. s = struct([ ]) creates an empty (0-by-0) structure with no fields.
Module 8: Generating normal and integer random numbers (1-D & 2-D) and plotting them; Also,
Writing a Script (which keeps running until no number is provided to convert) that asks for Temperature
in degrees Fahrenheit and Computes the Equivalent Temperature in degrees Celsius. [Hint: Function is empty is
useful]
Module 9: Writing brief Scripts starting each Script with a request for input (using input) to Evaluate the
function h(T) using if-else statement, where
h(T) = (T – 10) for 0 < T < 100
= (0.45 T + 900) for T > 100.
Exercise: Testing the Scripts written using (A). T = 5, h = -5 and (B). T = 110, h = 949.5
Also, Creating a Graphical User Interface (GUI); And, Curve Fitting using (A) Straight line Fit (B). Least Squares
Fit.
Functions:
1. p = polyfit(x,y,n) finds the coefficients of a polynomial p(x) of degree n that fits the data, p(x(i)) to
y(i), in a least squares sense. The result p is a row vector of length n+1 containing the polynomial
coefficients in descending powers:
2. y = polyval(p,x) returns the value of a polynomial of degree n evaluated at x. The input argument p
is a vector of length n+1 whose elements are the coefficients in descending powers of the polynomial
to be evaluated.
y = p1xn
+ p2xn–1
+ …+ pnx + pn+1
x can be a matrix or a vector. In either case, polyval evaluates p at each element of x.
Module 10: Interpolation based on following Schemes (A). Linear (B). Cubic (C). Spline Also, Generating
the first Ten Fibonacci numbers according to the relation Fn = Fn-1 + Fn-2 with F0 = F1 = 1, and Computing the
ratio Fn / Fn-1 for the first 50 Fibonacci numbers.
[Exercise: Verifying that the computed ratio approaches the value of the golden mean (1 + sqrt(5)) / 2 ]; Also
Generating Equivalent Square Wave from a Sine Wave of given Amplitude and Frequency; And,. Obtaining
the Covariance & Correlation Coefficient Matrices for a given Data Matrix.
Functions:
1. yi = interp1(x,Y,xi) interpolates to find yi, the values of the underlying function Y at the points in the
vector or array xi. x must be a vector. Y can be a scalar, a vector, or an array of any dimension, subject
to the following conditions:
a. If Y is a vector, it must have the same length as x. A scalar value for Y is expanded to have
the same length as x. xi can be a scalar, a vector, or a multidimensional array, and yi has the
same size as xi.
b. If Y is an array that is not a vector, the size of Y must have the form [n,d1,d2,...,dk], where n
is the length of x. The interpolation is performed for each d1-by-d2-by-...-dk value in Y. The
sizes of xi and yi are related as follows:
i. If xi is a scalar or vector, size(yi) equals [length(xi), d1, d2, ..., dk].
ii. If xi is an array of size [m1,m2,...,mj], yi has size [m1,m2,...,mj,d1,d2,...,dk].
Example:
Generate a coarse sine curve and interpolate over a finer abscissa.
x = 0:10;
y = sin(x);
xi = 0:.25:10;
yi = interp1(x,y,xi);
plot(x,y,'o',xi,yi)
2. yy = spline(x,Y,xx) uses a cubic spline interpolation to find yy, the values of the underlying function
Y at the values of the interpolant xx. For the interpolation, the independent variable is assumed to be
the final dimension of Y with the breakpoints defined by x. The sizes of xx and yy are related as
follows:
a. If Y is a scalar or vector, yy has the same size as xx.
b. If Y is an array that is not a vector,
i. If xx is a scalar or vector, size(yy) equals [d1, d2, ..., dk, length(xx)].
ii. If xx is an array of size [m1,m2,...,mj], size(yy) equals [d1,d2,...,dk,m1,m2,...,mj].
Example:
This generates a sine curve, then samples the spline over a finer mesh. x = 0:10;
y = sin(x);
xx = 0:.25:10;
yy = spline(x,y,xx);
plot(x,y,'o',xx,yy)

More Related Content

What's hot

Part I:Introduction to assembly language
Part I:Introduction to assembly languagePart I:Introduction to assembly language
Part I:Introduction to assembly languageAhmed M. Abed
Β 
Kleene's theorem
Kleene's theoremKleene's theorem
Kleene's theoremSamita Mukesh
Β 
Introduction to intel galileo board gen2
Introduction to intel galileo board gen2Introduction to intel galileo board gen2
Introduction to intel galileo board gen2Harshit Srivastava
Β 
Trends in Computer Graphics
Trends in Computer GraphicsTrends in Computer Graphics
Trends in Computer GraphicsSajal Maharjan
Β 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesLine Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesOmprakash Chauhan
Β 
Closure properties of context free grammar
Closure properties of context free grammarClosure properties of context free grammar
Closure properties of context free grammarAfshanKhan51
Β 
Computer graphics basic transformation
Computer graphics basic transformationComputer graphics basic transformation
Computer graphics basic transformationSelvakumar Gna
Β 
3 describing syntax
3 describing syntax3 describing syntax
3 describing syntaxMunawar Ahmed
Β 
Data converter fundamentals
Data converter fundamentalsData converter fundamentals
Data converter fundamentalsAbhishek Kadam
Β 
Sequential circuits in Digital Electronics
Sequential circuits in Digital ElectronicsSequential circuits in Digital Electronics
Sequential circuits in Digital ElectronicsVinoth Loganathan
Β 
Parallel projection
Parallel projectionParallel projection
Parallel projectionPrince Shahu
Β 
Parallel adder
Parallel adderParallel adder
Parallel adderKamil Hussain
Β 
Unit 6: DSP applications
Unit 6: DSP applicationsUnit 6: DSP applications
Unit 6: DSP applicationsMinakshi Atre
Β 
Composite transformations
Composite transformationsComposite transformations
Composite transformationsMohd Arif
Β 
Comparators in DLD.
Comparators in DLD.Comparators in DLD.
Comparators in DLD.Zain Jafri
Β 

What's hot (20)

Part I:Introduction to assembly language
Part I:Introduction to assembly languagePart I:Introduction to assembly language
Part I:Introduction to assembly language
Β 
Kleene's theorem
Kleene's theoremKleene's theorem
Kleene's theorem
Β 
Introduction to intel galileo board gen2
Introduction to intel galileo board gen2Introduction to intel galileo board gen2
Introduction to intel galileo board gen2
Β 
Assembly Language
Assembly LanguageAssembly Language
Assembly Language
Β 
Trends in Computer Graphics
Trends in Computer GraphicsTrends in Computer Graphics
Trends in Computer Graphics
Β 
Subroutine
SubroutineSubroutine
Subroutine
Β 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesLine Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - Notes
Β 
Closure properties of context free grammar
Closure properties of context free grammarClosure properties of context free grammar
Closure properties of context free grammar
Β 
Computer graphics basic transformation
Computer graphics basic transformationComputer graphics basic transformation
Computer graphics basic transformation
Β 
3 describing syntax
3 describing syntax3 describing syntax
3 describing syntax
Β 
Data converter fundamentals
Data converter fundamentalsData converter fundamentals
Data converter fundamentals
Β 
Sequential circuits in Digital Electronics
Sequential circuits in Digital ElectronicsSequential circuits in Digital Electronics
Sequential circuits in Digital Electronics
Β 
Lesson 05
Lesson 05Lesson 05
Lesson 05
Β 
Parallel projection
Parallel projectionParallel projection
Parallel projection
Β 
week1.ppt
week1.pptweek1.ppt
week1.ppt
Β 
Parallel adder
Parallel adderParallel adder
Parallel adder
Β 
Unit 6: DSP applications
Unit 6: DSP applicationsUnit 6: DSP applications
Unit 6: DSP applications
Β 
Pseudo code
Pseudo codePseudo code
Pseudo code
Β 
Composite transformations
Composite transformationsComposite transformations
Composite transformations
Β 
Comparators in DLD.
Comparators in DLD.Comparators in DLD.
Comparators in DLD.
Β 

Similar to matlab functions

02 linear algebra
02 linear algebra02 linear algebra
02 linear algebraHusseinZein5
Β 
02 linear algebra
02 linear algebra02 linear algebra
02 linear algebraRonald Teo
Β 
Matlab tut3
Matlab tut3Matlab tut3
Matlab tut3Vinnu Vinay
Β 
1. Introduction.pptx
1. Introduction.pptx1. Introduction.pptx
1. Introduction.pptxSungaleliYuen
Β 
Linear Algebra Presentation including basic of linear Algebra
Linear Algebra Presentation including basic of linear AlgebraLinear Algebra Presentation including basic of linear Algebra
Linear Algebra Presentation including basic of linear AlgebraMUHAMMADUSMAN93058
Β 
Linear_Algebra_final.pdf
Linear_Algebra_final.pdfLinear_Algebra_final.pdf
Linear_Algebra_final.pdfRohitAnand125
Β 
Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks
Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeksBeginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks
Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeksJinTaek Seo
Β 
Engg maths k notes(4)
Engg maths k notes(4)Engg maths k notes(4)
Engg maths k notes(4)Ranjay Kumar
Β 
Chapter 2 1
Chapter 2 1Chapter 2 1
Chapter 2 1abadi saied
Β 
presentationonmatrix-160801150449 (1).pptx
presentationonmatrix-160801150449 (1).pptxpresentationonmatrix-160801150449 (1).pptx
presentationonmatrix-160801150449 (1).pptxAhmadSajjad34
Β 
ahmad ppt discreet.pptx
ahmad ppt discreet.pptxahmad ppt discreet.pptx
ahmad ppt discreet.pptxAhmadSajjad34
Β 
Chapter 03-group-theory (1)
Chapter 03-group-theory (1)Chapter 03-group-theory (1)
Chapter 03-group-theory (1)ν•œμ„ λ‚˜
Β 
Matrices y determinants
Matrices y determinantsMatrices y determinants
Matrices y determinantsJeannie
Β 
Data transformation-cheatsheet
Data transformation-cheatsheetData transformation-cheatsheet
Data transformation-cheatsheetDieudonne Nahigombeye
Β 

Similar to matlab functions (20)

02 linear algebra
02 linear algebra02 linear algebra
02 linear algebra
Β 
02 linear algebra
02 linear algebra02 linear algebra
02 linear algebra
Β 
Matlab practical ---4.pdf
Matlab practical ---4.pdfMatlab practical ---4.pdf
Matlab practical ---4.pdf
Β 
Matlab tut3
Matlab tut3Matlab tut3
Matlab tut3
Β 
Commands list
Commands listCommands list
Commands list
Β 
1. Introduction.pptx
1. Introduction.pptx1. Introduction.pptx
1. Introduction.pptx
Β 
Linear Algebra Presentation including basic of linear Algebra
Linear Algebra Presentation including basic of linear AlgebraLinear Algebra Presentation including basic of linear Algebra
Linear Algebra Presentation including basic of linear Algebra
Β 
Linear_Algebra_final.pdf
Linear_Algebra_final.pdfLinear_Algebra_final.pdf
Linear_Algebra_final.pdf
Β 
Matrices
MatricesMatrices
Matrices
Β 
Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks
Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeksBeginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks
Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks
Β 
Engg maths k notes(4)
Engg maths k notes(4)Engg maths k notes(4)
Engg maths k notes(4)
Β 
Matlab operators
Matlab operatorsMatlab operators
Matlab operators
Β 
Matlab operators
Matlab operatorsMatlab operators
Matlab operators
Β 
Chapter 2 1
Chapter 2 1Chapter 2 1
Chapter 2 1
Β 
Brute force
Brute forceBrute force
Brute force
Β 
presentationonmatrix-160801150449 (1).pptx
presentationonmatrix-160801150449 (1).pptxpresentationonmatrix-160801150449 (1).pptx
presentationonmatrix-160801150449 (1).pptx
Β 
ahmad ppt discreet.pptx
ahmad ppt discreet.pptxahmad ppt discreet.pptx
ahmad ppt discreet.pptx
Β 
Chapter 03-group-theory (1)
Chapter 03-group-theory (1)Chapter 03-group-theory (1)
Chapter 03-group-theory (1)
Β 
Matrices y determinants
Matrices y determinantsMatrices y determinants
Matrices y determinants
Β 
Data transformation-cheatsheet
Data transformation-cheatsheetData transformation-cheatsheet
Data transformation-cheatsheet
Β 

More from DINESH DEVIREDDY

Project on digital vlsi design
Project on digital vlsi designProject on digital vlsi design
Project on digital vlsi designDINESH DEVIREDDY
Β 
Marketing and the psychology of persuasion
Marketing and the psychology of persuasionMarketing and the psychology of persuasion
Marketing and the psychology of persuasionDINESH DEVIREDDY
Β 
PSYCHOMETRICS INDIVIDUAL AND GROUP TESTS
 PSYCHOMETRICS INDIVIDUAL AND GROUP TESTS PSYCHOMETRICS INDIVIDUAL AND GROUP TESTS
PSYCHOMETRICS INDIVIDUAL AND GROUP TESTSDINESH DEVIREDDY
Β 
Microcontroller project
Microcontroller projectMicrocontroller project
Microcontroller projectDINESH DEVIREDDY
Β 
Binary to gray converter using xor
Binary to gray converter using xor Binary to gray converter using xor
Binary to gray converter using xor DINESH DEVIREDDY
Β 
WATER RESOURCES IN INDIA
WATER RESOURCES IN INDIAWATER RESOURCES IN INDIA
WATER RESOURCES IN INDIADINESH DEVIREDDY
Β 
Narration concepts ppt
Narration concepts  pptNarration concepts  ppt
Narration concepts pptDINESH DEVIREDDY
Β 

More from DINESH DEVIREDDY (7)

Project on digital vlsi design
Project on digital vlsi designProject on digital vlsi design
Project on digital vlsi design
Β 
Marketing and the psychology of persuasion
Marketing and the psychology of persuasionMarketing and the psychology of persuasion
Marketing and the psychology of persuasion
Β 
PSYCHOMETRICS INDIVIDUAL AND GROUP TESTS
 PSYCHOMETRICS INDIVIDUAL AND GROUP TESTS PSYCHOMETRICS INDIVIDUAL AND GROUP TESTS
PSYCHOMETRICS INDIVIDUAL AND GROUP TESTS
Β 
Microcontroller project
Microcontroller projectMicrocontroller project
Microcontroller project
Β 
Binary to gray converter using xor
Binary to gray converter using xor Binary to gray converter using xor
Binary to gray converter using xor
Β 
WATER RESOURCES IN INDIA
WATER RESOURCES IN INDIAWATER RESOURCES IN INDIA
WATER RESOURCES IN INDIA
Β 
Narration concepts ppt
Narration concepts  pptNarration concepts  ppt
Narration concepts ppt
Β 

Recently uploaded

Best VIP Call Girls Noida Sector 47 Call Me: 8448380779
Best VIP Call Girls Noida Sector 47 Call Me: 8448380779Best VIP Call Girls Noida Sector 47 Call Me: 8448380779
Best VIP Call Girls Noida Sector 47 Call Me: 8448380779Delhi Call girls
Β 
MASONRY -Building Technology and Construction
MASONRY -Building Technology and ConstructionMASONRY -Building Technology and Construction
MASONRY -Building Technology and Constructionmbermudez3
Β 
DragonBall PowerPoint Template for demo.pptx
DragonBall PowerPoint Template for demo.pptxDragonBall PowerPoint Template for demo.pptx
DragonBall PowerPoint Template for demo.pptxmirandajeremy200221
Β 
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...Suhani Kapoor
Β 
NO1 Trending kala jadu Love Marriage Black Magic Punjab Powerful Black Magic ...
NO1 Trending kala jadu Love Marriage Black Magic Punjab Powerful Black Magic ...NO1 Trending kala jadu Love Marriage Black Magic Punjab Powerful Black Magic ...
NO1 Trending kala jadu Love Marriage Black Magic Punjab Powerful Black Magic ...Amil baba
Β 
PODSCAPE - Brochure 2023_ prefab homes in Bangalore India
PODSCAPE - Brochure 2023_ prefab homes in Bangalore IndiaPODSCAPE - Brochure 2023_ prefab homes in Bangalore India
PODSCAPE - Brochure 2023_ prefab homes in Bangalore IndiaYathish29
Β 
Fashion trends before and after covid.pptx
Fashion trends before and after covid.pptxFashion trends before and after covid.pptx
Fashion trends before and after covid.pptxVanshNarang19
Β 
WAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsWAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsCharles Obaleagbon
Β 
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...Call Girls in Nagpur High Profile
Β 
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 night
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 nightCheap Rate Call girls Malviya Nagar 9205541914 shot 1500 night
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 nightDelhi Call girls
Β 
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...Suhani Kapoor
Β 
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130Suhani Kapoor
Β 
SD_The MATATAG Curriculum Training Design.pptx
SD_The MATATAG Curriculum Training Design.pptxSD_The MATATAG Curriculum Training Design.pptx
SD_The MATATAG Curriculum Training Design.pptxjanettecruzeiro1
Β 
CALL ON βž₯8923113531 πŸ”Call Girls Kalyanpur Lucknow best Female service 🧡
CALL ON βž₯8923113531 πŸ”Call Girls Kalyanpur Lucknow best Female service  🧡CALL ON βž₯8923113531 πŸ”Call Girls Kalyanpur Lucknow best Female service  🧡
CALL ON βž₯8923113531 πŸ”Call Girls Kalyanpur Lucknow best Female service 🧡anilsa9823
Β 
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiVIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiSuhani Kapoor
Β 
Call Girls in Kalkaji Delhi 8264348440 call girls ❀️
Call Girls in Kalkaji Delhi 8264348440 call girls ❀️Call Girls in Kalkaji Delhi 8264348440 call girls ❀️
Call Girls in Kalkaji Delhi 8264348440 call girls ❀️soniya singh
Β 
A level Digipak development Presentation
A level Digipak development PresentationA level Digipak development Presentation
A level Digipak development Presentationamedia6
Β 

Recently uploaded (20)

Best VIP Call Girls Noida Sector 47 Call Me: 8448380779
Best VIP Call Girls Noida Sector 47 Call Me: 8448380779Best VIP Call Girls Noida Sector 47 Call Me: 8448380779
Best VIP Call Girls Noida Sector 47 Call Me: 8448380779
Β 
MASONRY -Building Technology and Construction
MASONRY -Building Technology and ConstructionMASONRY -Building Technology and Construction
MASONRY -Building Technology and Construction
Β 
Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance VVIP 🍎 SER...
Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance  VVIP 🍎 SER...Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance  VVIP 🍎 SER...
Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance VVIP 🍎 SER...
Β 
DragonBall PowerPoint Template for demo.pptx
DragonBall PowerPoint Template for demo.pptxDragonBall PowerPoint Template for demo.pptx
DragonBall PowerPoint Template for demo.pptx
Β 
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
Β 
NO1 Trending kala jadu Love Marriage Black Magic Punjab Powerful Black Magic ...
NO1 Trending kala jadu Love Marriage Black Magic Punjab Powerful Black Magic ...NO1 Trending kala jadu Love Marriage Black Magic Punjab Powerful Black Magic ...
NO1 Trending kala jadu Love Marriage Black Magic Punjab Powerful Black Magic ...
Β 
PODSCAPE - Brochure 2023_ prefab homes in Bangalore India
PODSCAPE - Brochure 2023_ prefab homes in Bangalore IndiaPODSCAPE - Brochure 2023_ prefab homes in Bangalore India
PODSCAPE - Brochure 2023_ prefab homes in Bangalore India
Β 
Fashion trends before and after covid.pptx
Fashion trends before and after covid.pptxFashion trends before and after covid.pptx
Fashion trends before and after covid.pptx
Β 
WAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsWAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past Questions
Β 
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
Β 
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 night
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 nightCheap Rate Call girls Malviya Nagar 9205541914 shot 1500 night
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 night
Β 
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...
Β 
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
Β 
SD_The MATATAG Curriculum Training Design.pptx
SD_The MATATAG Curriculum Training Design.pptxSD_The MATATAG Curriculum Training Design.pptx
SD_The MATATAG Curriculum Training Design.pptx
Β 
CALL ON βž₯8923113531 πŸ”Call Girls Kalyanpur Lucknow best Female service 🧡
CALL ON βž₯8923113531 πŸ”Call Girls Kalyanpur Lucknow best Female service  🧡CALL ON βž₯8923113531 πŸ”Call Girls Kalyanpur Lucknow best Female service  🧡
CALL ON βž₯8923113531 πŸ”Call Girls Kalyanpur Lucknow best Female service 🧡
Β 
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiVIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
Β 
young call girls in Vivek ViharπŸ” 9953056974 πŸ” Delhi escort Service
young call girls in Vivek ViharπŸ” 9953056974 πŸ” Delhi escort Serviceyoung call girls in Vivek ViharπŸ” 9953056974 πŸ” Delhi escort Service
young call girls in Vivek ViharπŸ” 9953056974 πŸ” Delhi escort Service
Β 
Call Girls in Kalkaji Delhi 8264348440 call girls ❀️
Call Girls in Kalkaji Delhi 8264348440 call girls ❀️Call Girls in Kalkaji Delhi 8264348440 call girls ❀️
Call Girls in Kalkaji Delhi 8264348440 call girls ❀️
Β 
young call girls in Pandav nagar πŸ” 9953056974 πŸ” Delhi escort Service
young call girls in Pandav nagar πŸ” 9953056974 πŸ” Delhi escort Serviceyoung call girls in Pandav nagar πŸ” 9953056974 πŸ” Delhi escort Service
young call girls in Pandav nagar πŸ” 9953056974 πŸ” Delhi escort Service
Β 
A level Digipak development Presentation
A level Digipak development PresentationA level Digipak development Presentation
A level Digipak development Presentation
Β 

matlab functions

  • 1. CSE222: Basic Simulation lab Functions (MatLab) Module 1: Creating a One-Dimensional Array (Row / Column Vector) Exercise – Creating a vector of even whole numbers between 31 and 75; Creating a Two-Dimensional Array (Matrix of given size) and (A). Performing Arithmetic Operations - Addition, Subtraction, Multiplication and Exponentiation. (B). Obtaining Modified Matrix - Inverse, Transpose, with Appended and Deleted Elements; Module 2: Performing Matrix Manipulations - Concatenating, Indexing, Sorting, Shifting, Reshaping, Resizing and Flipping about a Vertical Axis/Horizontal Axis; Creating Arrays X & Y of given size (1 x N) and Performing (A) Relational Operations - >, <, ==, <=, >=, ~= (B) Logical Operations - ~, &, |, XOR Functions: 1. Concatenation C = [A B] horizontally concatenates matrices A and B C = [A; B] vertically concatenates matrices A and B For building a matrix horizontally, each component matrix must have the same number of rows. When building vertically, each component must have the same number of columns. C = cat(dim, A, B) concatenates the arrays A and B along array dimension dim. C = cat(dim, A1, A2, A3, A4, ...) concatenates all the input arrays (A1, A2, A3, A4, and so on) along array dimension dim. C = horzcat(A1, A2, ...) horizontally concatenates matrices A1, A2, and so on C = vertcat(A1, A2, ...) vertically concatenates matrices A1, A2, and so on 2. Indexing A(m, :) give the all values of mth row A(:, n) give the all values of nth column 3. Sorting sort(matrix, dimension) Dimension argument 1 sorts matrix columns. Dimension argument 2 sorts matrix rows. B = sort(A) sorts the elements along different dimensions of an array, and arranges those elements in ascending order. B = sort(A, dim) sorts the elements along the dimension of A specified by a scalar dim. B = sort(...,mode) sorts the elements in the specified direction, depending on the value of mode. 'ascend' Ascending order (default) 'descend' Descending order 4. Shifting B = circshift(A, shiftsize) circularly shifts the values in the array, A, by shiftsize elements 5. Reshaping and Resizing B = reshape(A,m,n) returns the m-by-n matrix B whose elements are taken column-wise from A. An error results if A does not have m*n elements. B = reshape(A,m,n,p,...) or B= reshape(A,[m n p ...]) returns an n-dimensional array with the same elements as A but reshaped to have the size m-by-n-by-p-by-.... The product of the specified dimensions, m*n*p*..., must be the same as prod(size(A)). B = rot90(A) rotates matrix A counterclockwise by 90 degrees. B = rot90(A,k) rotates matrix A counterclockwise by k*90 degrees, where k is an integer. 6. Flipping B = fliplr(A) returns A with columns flipped in the left-right direction, that is, about a vertical axis.
  • 2. B = flipud(A) returns A with rows flipped in the up-down direction, that is, about a horizontal axis. B = flipdim(A,dim) returns A with dimension dim flipped. When the value of dim is 1, the array is flipped row-wise down. When dim is 2, the array is flipped columnwise left to right. flipdim(A,1) is the same as flipud(A), and flipdim(A,2) is the same as fliplr(A). 7. Relational Operations A < B A > B A <= B A >= B A == B A ~= B The relational operators are <, >, <=, >=, ==, and ~=. Relational operators perform element- by-element comparisons between two arrays. They return a logical array of the same size, with elements set to logical 1 (true) where the relation is true, and elements set to logical 0 (false) where it is not.The operators <, >, <=, and >= use only the real part of their operands for the comparison. The operators == and ~= test real and imaginary parts. 8. Logical Operations A & B A| B ~A The symbols &, |, and ~ are the logical array operators AND, OR, and NOT. These operators are commonly used in conditional statements, such as if and while, to determine whether or not to execute a particular block of code. Logical operations return a logical array with elements set to 1 (true) or 0 (false), as appropriate. xor(A,B) represents the logical exclusive disjunction. xor(A,B) is true when either A or B are true. If both A and B are true or false, xor(A,B) is false. Module 3: Generating a set of Commands on a given Vector (Example: X = [1 8 3 9 0 1]) to (A) Add up the values of the elements (Check with sum) (B) Compute the Running Sum (Check with sum), where Running Sum for element j = the sum of the elements from 1 to j, inclusive. (C) Compute the Sine of the given X-values (should be a vector). Also, Generating a Random Sequence using rand() / randn() functions and plotting them. Functions: 1. Sum B = sum(A) returns sums along different dimensions of an array. If A is floating point, that is double or single, B is accumulated natively, that is in the same class as A, and B has the same class as A. If A is not floating point, B is accumulated in double and B has class double. If A is a vector, sum(A) returns the sum of the elements. If A is a matrix, sum(A) treats the columns of A as vectors, returning a row vector of the sums of each column. If A is a multidimensional array, sum(A) treats the values along the first non-singleton dimension as vectors, returning an array of row vectors. B = sum(A,dim) sums along the dimension of A specified by scalar dim. The dim input is an integer value from 1 to N, where N is the number of dimensions in A. Set dim to 1 to compute the sum of each column, 2 to sum rows, etc. B = cumsum(A) returns the cumulative sum along different dimensions of an array. If A is a vector, cumsum(A) returns a vector containing the cumulative sum of the elements of A. If A is a matrix, cumsum(A) returns a matrix the same size as A containing the cumulative sums for each column of A. If A is a multidimensional array, cumsum(A) works on the first nonsingleton dimension. B = cumsum(A,dim) returns the cumulative sum of the elements along the dimension of A specified by scalar dim. For example, cumsum(A,1) works along the first dimension (the columns); cumsum(A,2) works along the second dimension (the rows).
  • 3. 2. Sine function Y = sin(X) returns the circular sine of the elements of X. The sin function operates element- wise on arrays. The function's domains and ranges include complex values. All angles are in radians. 3. rand() r = rand(n) returns an n-by-n matrix containing pseudorandom values drawn from the standard uniform distribution on the open interval (0,1). r = rand(m,n) or r = rand([m,n]) returns an m-by-n matrix. r = rand(m,n,p,...) or r = rand([m,n,p,...]) returns an m-by-n-by-p-by-... array. r = rand returns a scalar. r = rand(size(A)) returns an array the same size as A. 4. randn() r = randn(n) returns an n-by-n matrix containing pseudorandom values drawn from the standard normal distribution. r = randn(m,n) or r = randn([m,n]) returns an m-by-n matrix. r = randn(m,n,p,...) or r = randn([m,n,p,...]) returns an m-by-n-by-p-by-... array. r = randn returns a scalar. r = randn(size(A)) returns an array the same size as A. 5. plot() plot(Y) plots the columns of Y versus the index of each value when Y is a real number. For complex Y, plot(Y) is equivalent to plot(real(Y),imag(Y)) Module 4: Evaluating a given expression and rounding it to the nearest integer value using Round, Floor, Ceil and Fix functions; Also, generating and Plots of (A) Trigonometric Functions - sin(t), cos(t), tan(t), sec(t), cosec(t) and cot(t) for a given duration β€˜t’. (B) Logarithmic and other Functions – log(A), log10(A), Square root of A, Real nth root of A. Functions: 1. Round Y = round(X) rounds the elements of X to the nearest integers. Positive elements with a fractional part of 0.5 round up to the nearest positive integer. Negative elements with a fractional part of -0.5 round down to the nearest negative integer. For complex X, the imaginary and real parts are rounded independently. 2. Floor B = floor(A) rounds the elements of A to the nearest integers less than or equal to A. For complex A, the imaginary and real parts are rounded independently. 3. Ceil B = ceil(A) rounds the elements of A to the nearest integers greater than or equal to A. For complex A, the imaginary and real parts are rounded independently. 4. Fix B = fix(A) rounds the elements of A toward zero, resulting in an array of integers. For complex A, the imaginary and real parts are rounded independently. Example:- a = [-1.9, -0.2, 3.4, 5.6, 7.0, 2.4+3.6i] a = -1.9000 -0.2000 3.4000 5.6000 7.0000 2.4000 + 3.6000i >> round(a) ans = -2.0000 0 3.0000 6.0000 7.0000 2.0000 + 4.0000i >> floor(a) ans = -2.0000 -1.0000 3.0000 5.0000 7.0000 2.0000 + 3.0000i >> ceil(a) ans = -1.0000 0 4.0000 6.0000 7.0000 3.0000 + 4.0000i >> fix(a)
  • 4. ans = -1.0000 0 3.0000 5.0000 7.0000 2.0000 + 3.0000i 5. Square root B = sqrt(X) returns the square root of each element of the array X. For the elements of X that are negative or complex, sqrt(X) produces complex results. 6. Real nth root y = nthroot(X, n) returns the real nth root of the elements of X. Both X and n must be real and n must be a scalar. If X has negative entries, n must be an odd integer. Module 5: Creating a vector X with elements, Xn = (-1)n+1 /(2n-1) and Adding up 100 elements of the vector, X; And, plotting the functions, x, x3 , ex and exp(x2 ) over the interval 0 < x < 4 (by choosing appropriate mesh values for x to obtain smooth curves), on (A). A Rectangular Plot (B). A Semi log Plot (C). A log-log Plot Module 6: Generating a Sinusoidal Signal of a given frequency (say, 100Hz) and Plotting with Graphical Enhancements - Titling, Labelling, Adding Text, Adding Legends, Adding New Plots to Existing Plot, Printing Text in Greek Letters, Plotting as Multiple and Subplots; Also, Making Non-Choppy and Smooth Plot of the functions, f(x) = sin(1/x) for 0.01< x < 0.1 and g(x) = (sin x) /x. Module 7: Creating a Structure, an Array of Structures and Writing Commands to Access Elements of the created Structure and Array of Structures; Also, Solving First Order Ordinary Differential Equation using Built- in Functions; And, Creating an M x N Array of Random Numbers using rand and setting any value that is < 0.2 to β€˜0’ and any value that is β‰₯ 0.2 to β€˜1’ by moving through the Array, Element by Element. Functions: 1. s = struct creates a scalar (1-by-1) structure with no fields. 2. s = struct(field,value) creates a structure array with the specified field and values. Example: Create a nonscalar structure with one field, f. field = 'f'; value = {'some text'; [10, 20, 30]; magic(5)}; s = struct(field,value) s = 3x1 struct array with fields: f View the contents each element. s.f ans = some text ans = 10 20 30 ans = 17 24 1 8 15 23 5 7 14 16
  • 5. 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 When you access a field of a nonscalar structure, such as s.f, MATLAB returns a comma-separated list. In this case, s.f is equivalent to s(1).f, s(2).f, s(3).f. 3. s = struct(field1,value1,...,fieldN,valueN) creates a structure array Example Create a nonscalar structure with several fields. field1 = 'f1'; value1 = zeros(1,10); field2 = 'f2'; value2 = {'a', 'b'}; field3 = 'f3'; value3 = {pi, pi.^2}; field4 = 'f4'; value4 = {'fourth'}; s = struct(field1,value1,field2,value2,field3,value3,field4,value4) s = 1x2 struct array with fields: f1 f2 f3 f4 The cell arrays for value2 and value3 are 1-by-2, so s is also 1-by-2. Because value1 is a numeric array and not a cell array, both s(1).f1 and s(2).f1 have the same contents. Similarly, because the cell array for value4 has a single element, s(1).f4 and s(2).f4 have the same contents. s(1) ans = f1: [0 0 0 0 0 0 0 0 0 0] f2: 'a' f3: 3.1416 f4: 'fourth's(2)ans = f1: [0 0 0 0 0 0 0 0 0 0] f2: 'b' f3: 9.8696 f4: 'fourth' 4. s = struct([ ]) creates an empty (0-by-0) structure with no fields. Module 8: Generating normal and integer random numbers (1-D & 2-D) and plotting them; Also, Writing a Script (which keeps running until no number is provided to convert) that asks for Temperature in degrees Fahrenheit and Computes the Equivalent Temperature in degrees Celsius. [Hint: Function is empty is useful] Module 9: Writing brief Scripts starting each Script with a request for input (using input) to Evaluate the function h(T) using if-else statement, where h(T) = (T – 10) for 0 < T < 100 = (0.45 T + 900) for T > 100. Exercise: Testing the Scripts written using (A). T = 5, h = -5 and (B). T = 110, h = 949.5 Also, Creating a Graphical User Interface (GUI); And, Curve Fitting using (A) Straight line Fit (B). Least Squares Fit.
  • 6. Functions: 1. p = polyfit(x,y,n) finds the coefficients of a polynomial p(x) of degree n that fits the data, p(x(i)) to y(i), in a least squares sense. The result p is a row vector of length n+1 containing the polynomial coefficients in descending powers: 2. y = polyval(p,x) returns the value of a polynomial of degree n evaluated at x. The input argument p is a vector of length n+1 whose elements are the coefficients in descending powers of the polynomial to be evaluated. y = p1xn + p2xn–1 + …+ pnx + pn+1 x can be a matrix or a vector. In either case, polyval evaluates p at each element of x. Module 10: Interpolation based on following Schemes (A). Linear (B). Cubic (C). Spline Also, Generating the first Ten Fibonacci numbers according to the relation Fn = Fn-1 + Fn-2 with F0 = F1 = 1, and Computing the ratio Fn / Fn-1 for the first 50 Fibonacci numbers. [Exercise: Verifying that the computed ratio approaches the value of the golden mean (1 + sqrt(5)) / 2 ]; Also Generating Equivalent Square Wave from a Sine Wave of given Amplitude and Frequency; And,. Obtaining the Covariance & Correlation Coefficient Matrices for a given Data Matrix. Functions: 1. yi = interp1(x,Y,xi) interpolates to find yi, the values of the underlying function Y at the points in the vector or array xi. x must be a vector. Y can be a scalar, a vector, or an array of any dimension, subject to the following conditions: a. If Y is a vector, it must have the same length as x. A scalar value for Y is expanded to have the same length as x. xi can be a scalar, a vector, or a multidimensional array, and yi has the same size as xi. b. If Y is an array that is not a vector, the size of Y must have the form [n,d1,d2,...,dk], where n is the length of x. The interpolation is performed for each d1-by-d2-by-...-dk value in Y. The sizes of xi and yi are related as follows: i. If xi is a scalar or vector, size(yi) equals [length(xi), d1, d2, ..., dk]. ii. If xi is an array of size [m1,m2,...,mj], yi has size [m1,m2,...,mj,d1,d2,...,dk]. Example: Generate a coarse sine curve and interpolate over a finer abscissa. x = 0:10; y = sin(x); xi = 0:.25:10; yi = interp1(x,y,xi); plot(x,y,'o',xi,yi) 2. yy = spline(x,Y,xx) uses a cubic spline interpolation to find yy, the values of the underlying function Y at the values of the interpolant xx. For the interpolation, the independent variable is assumed to be the final dimension of Y with the breakpoints defined by x. The sizes of xx and yy are related as follows: a. If Y is a scalar or vector, yy has the same size as xx. b. If Y is an array that is not a vector, i. If xx is a scalar or vector, size(yy) equals [d1, d2, ..., dk, length(xx)]. ii. If xx is an array of size [m1,m2,...,mj], size(yy) equals [d1,d2,...,dk,m1,m2,...,mj]. Example: This generates a sine curve, then samples the spline over a finer mesh. x = 0:10; y = sin(x); xx = 0:.25:10; yy = spline(x,y,xx); plot(x,y,'o',xx,yy)