Basics of MATLAB.

Download as pdf or txt
Download as pdf or txt
You are on page 1of 133

G Madegowda Institute of Technology

DEPARTMENT OF MECHANICAL
ENGINEERING

LAB MANUAL

BASICS OF MAT LAB


21ME581

Prepared by-
Mr Sudhir B S
AY 2023 - 24
IBASICS OF MATILAB
Course Code 2lME581 CIE Marks 50
Teaching Hours/Week (L:T:P: S) 0:0:2 ':0 SEE Marks 50
Credits 01 Exam HOtffS 02
* Ad,dition,at one hou.r may be considered for instructions, if required
Course objectives:
1. To kriow about fundamentals of MATLAB tool.
2. To provide an overview to program CtJrve fitting & solve linear and Nonlinear Equatiions.
3. To understand the concept and importance of Fourier tiransforms.
4. To gain knowledge abotJt MATLAB Simulink & solve Electrical engineering problems.

SI.NO Experiments
1
Introduction to MATLAB Programming: Basicsof MATLAB Programming, array operations in MATLAB, loops
2 and execution of control, working with files: Scripts and fonction.s, plotting and programming outpllt, examples.

Numerical! Methods and their applications: Curve Fining: Straigiht lineii, Poll1inomiallit.
4

Numerical! Integration and Dif rentiatio1n: Trapezoidal method, Sfmpson method.


6

7
Linear and N,onlinear Equatiions: IEigen values, Eigen vectors, Solution of linear algebraic equations using GatJss
Elimination and LU decomposition, Solution •Of nonlinear equation in single varliable using Gauss-Siedal and
8
Newton-Raphson method.

9
Oirdinall"VIDiffeirential E.quation.s: Introduction to ODE's, Euler's method, second order RungaKutta method,
10 MATLAB ode45 algorithm in single variable and multivariables. Tiransfoirms: Discrete FotJrler Tran.sforms,

11
Application of MATLAB to analyse problems in basic engineering mechanics, mechanical vibrations, control
12 system, statistics and dynamicsof different circuits.
MATLAB Simullinlk: Introduction to MATLAB Simulink, Simulink libraries,d, evelopment of basic models in
13 Simscape Power Systems

Couirse outcomes (Cow1rse Skill Set):


At the end of the cotJrse the student will be able to:

• .Able to implement loops, branching, control instriuctiion and fonctions in MATLAB programming environment.
• .Able to program curve fitting, numerical differentiation and integration, solution of linear equations in MATILAIB
and solve electrical engineering problems.
• .Able to understand Implementation of ODE using ode 45 and execute Solutions of nonlinear equations and DFT
in MA11LAB.
• .Able to srmulate MAHAIB Simlllink examples
INTRODUCTION TO MAT LAB

The name MATLAB stands for MATrix LABoratory. MATLAB was written originally to
provide easy access to matrix software developed by the LINPACK (linear system package)
and EISPACK (Eigen system package) projects.

MATLAB is a high-performance language for technical computing. It integrates computation,


visualization, and programming environment. Furthermore, MATLAB is a modern
programming language environment: it has sophisticated data structures, contains built-in
editing and debugging tools, and supports object-oriented programming. These factors make
MATLAB an excellent tool for teaching and research.

MATLAB is a high-performance language for technical computing. It integrates computation,


visualization, and programming in an easy-to-use environment where problems and solutions
are expressed in familiar mathematical notation. Typical uses include
 Math and computation
 Algorithm development
 Data acquisition
 Modeling, simulation, and prototyping
 Data analysis, exploration, and visualization

 Scientific and engineering graphics


 Application development, including graphical user interface building
Features of MATLAB
Following are the basic features of MATLAB:
 It is a high-level language for numerical computation, visualization and application
development.
 It also provides an interactive environment for iterative exploration, design and
problem solving.
 It provides vast library of mathematical functions for linear algebra, statistics,
Fourier analysis, filtering, optimization, numerical integration and solving ordinary
differentialequations.
 It provides built-in graphics for visualizing data and tools for creating custom plots.
 MATLAB's programming interface gives development tools for improving code
quality, maintainability, and maximizing performance.
 It provides tools for building applications with custom graphical interfaces.
 It provides functions for integrating MATLAB based algorithms with
external applications and languages such as C, Java, .NET and Microsoft
Excel.
Uses of MATLAB

 MATLAB is widely used as a computational tool in science and engineering


encompassing the fields of physics, chemistry, math and all engineering streams. It is
used in a range of applications including:
 signal processing and Communications
 image and video Processing
 control systems
 test and measurement
 computational finance
 computational biology

Starting MATLAB
After logging into your account, you can enter MATLAB by double-clicking on the
MATLAB shortcut icon (MATLAB 17.0.4) on your Windows desktop. When you start
MATLAB, a special window called the MATLAB desktop appears. The desktop is a window
that contains other windows. The major tools within or accessible from the desktop are:
 The Command Window
 The Command History
 The Workspace
 The Current Directory
 The Help Browser
 The Start button
Desktop Tools
The following tools are managed by the MATLAB desktop, although not all of them appear
by default when you first start. If you prefer a command line interface, you can use functions
to perform most of the features found in the MATLAB desktop tools. Instructions for using
these function equivalents are provided with the documentation for each tool.
 Command Window – Run MATLAB functions.
 Command History – View a log of the functions you entered in the Command
Window, copy them, and execute them.
 Launch Pad – Run tools and access documentation for all of your MathWorks
products.
 Current Directory Browser – View MATLAB files and related files, and perform
file operations such as open, and find content.
 Help Browser – View and search the documentation for the full family of MATLAB
products.
 Workspace Browser – View and make changes to the contents of the workspace.
 Array Editor – View array contents in a table format and edit the values.
 Editor/Debugger – Create, edit, and debug M-files (files containing MATLAB
functions).

Keyboard Shortcuts and Accelerators


You can access many of the menu items using keyboard shortcuts or accelerators for your
platform, such as using Ctrl+X to perform a Cut on Windows platforms, or Alt+F to open the
File menu. Many of the shortcuts and accelerators are listed with the menu item. For example,
on Windows platforms, the Edit menu shows Cut Ctrl+X, and the File menu shows the F in
File underlined, which indicates that Alt+X opens it. Many standard shortcuts for your
platform will work but are not listed with the menu items.

Following are some additional shortcuts that are not listed on menu items.

.
MATLAB Windows

Window Purpose

Command Window Main window, enters variables, runs programs

Figure Window Contains output from graphic commands

Editor Window Creates and debugs script and function files

Help Window Provides help information

Provides access to tools, demos, and


Launch Pad Window
documentation
Command History Window
Logs commands entered in the Command
Window
Workspace Window
Provides information about the variables that
are used
Current Directory Window
Shows the files in the current directory
Working in the Command Window

Notation Purpose

>> Command Prompt

Out put of the command is executed


(Enter key)

Recalled the previously typed command to the


(Upper and down command prompt
arrow keys)

… (Three periods) Command is continued to the next line

; (Semicolon) Out put of the command is not displayed

% (Enter key) It indicates that the line is designated as a comment

clc clears the command window

clear Removes all the variables from the memory

who Displays a list of the variables currently in the


memory
Displays a list of the variables currently in the
whos memory and their size together with information
about their bytes and class
Lab Program – 1&2

Introduction to MATLAB Programming: Basics of MATLAB Programming,


array operations in MATLAB, loops 2 and execution of control, working with
files: Scripts and functions, plotting and programming output, examples.

MATLAB environment behaves like a super-complex calculator. You can enter


commands at the >> command prompt.
MATLAB is an interpreted environment. In other words, you give a command
and MATLAB executes it right away.

Commonly used Operators and Special Characters

MATLAB supports the following commonly used operators and special


characters:
Operator Purpose

+ Plus; addition operator.

- Minus; subtraction operator.

* Scalar and matrix multiplication operator.

.* Array multiplication operator.

^ Scalar and matrix exponentiation operator.

.^ Array exponentiation operator.

\ Left-division operator.

/ Right-division operator.

.\ Array left-division operator.


./ Array right-division operator.

: Colon; generates regularly spaced elements and represents


an entire row or column.

() Parentheses; encloses function arguments and array indices;


overrides precedence.

[] Brackets; enclosures array elements.

. Decimal point.

… Ellipsis; line-continuation operator

, Comma; separates statements and elements in a row

; Semicolon; separates columns and suppresses display.

% Percent sign; designates a comment and specifies


formatting.

_ Quote sign and transpose operator.

._ Non-conjugated transpose operator.

= Assignment operator.

Hands on Practice

Type a valid expression, for example,


5+5
And press ENTER
When you click the Execute button, or type Ctrl+E, MATLAB executes it
immediately and the result returned is:
ans = 10
Let us take up few more examples:
3^2 % 3 raised to the power of 2
When you click the Execute button, or type Ctrl+E, MATLAB executes it
immediately and the result returned is:
ans = 9
Another example,
sin(pi /2) % sine of angle 900
When you click the Execute button, or type Ctrl+E, MATLAB executes it
immediately and the result returned is:
ans = 1

Semicolon (;) indicates end of statement. However, if you want to suppress and
hide the MATLAB output for an expression, add a semicolon after the
expression.
For example,
x = 3;

y=x+5
When you click the Execute button, or type Ctrl+E, MATLAB executes it
immediately and the result returned is:
y=8

Some more Examples

>> 7+8/2 ← Type and press enter


( → 8/2 is executed first )
ans = 11

>> (7+8)/2 ← Type and press enter


→ 7+8 is executed first
ans = 7.5000

>> 4 + 5/3 + 2
→ 5/3 is executed first
ans = 7.6667
>> 5 ^3/2
→ 5^3 is executed first, /2 is executed next
ans = 62.5000

>> 27^(1/3)+32^0.2
→ 1/3 is executed first, 27^(1/3) and 32^0.2 are executed next, and + is executed
last

Ans = 5

>> 27^1/3+32^0.2
→ 27^1/3 and 32^0.2 are executed first, 1/3 is executed next, and + is executed
last
Ans = 11

>> 0.7854 (0.7854)^3/(1*2*3)+0.7854^5/(1*2*3*4*5)...


type three periods … and press enter to continue the expression on the next line
-0.7854^7/(1*2*3*4*5*6*7)
Ans = 0.7071

The format Command

By default, MATLAB displays numbers with four decimal place values. This is
known as short format.
However, if you want more precision, you need to use the format command.
The format long command displays 16 digits after decimal.
For example:
format long
x = 7 + 10/3 + 5 ^ 1.2

MATLAB will execute the above statement and return the following result:
x = 17.231981640639408

format short
x = 7 + 10/3 + 5 ^ 1.2

MATLAB will execute the above statement and return the following result:
x = 17.2320

The format bank command rounds numbers to two decimal places. For
example,

format bank
daily_wage = 177.45;
weekly_wage = daily_wage * 6

MATLAB will execute the above statement and return the following result:
weekly_wage = 1064.70

MATLAB displays large numbers using exponential notation.

The format short e command allows displaying in exponential form with four
decimal places plus the exponent. For example,
format short e
4.678 * 4.9

MATLAB will execute the above statement and return the following result:
ans = 2.2922e+01

The format long e command allows displaying in exponential form with four
decimal places plus the exponent. For example,

format long e
x = pi

MATLAB will execute the above statement and return the following result:
x = 3.141592653589793e+00

The format rat command gives the closest rational expression resulting from a
calculation. For example,
format rat
4.678 * 4.9

MATLAB will execute the above statement and return the following result:
Ans =2063/90
Some more Examples

Command Description
Examples

format short Fixed-point with 4 >> format short


decimal digits >> 290/7
ans = 41.4286

format long Fixed-point with 14 >> format long


decimal digits >> 290/7
Ans = 41.42857142857143
format short e Scientific notation >> format short e
with 4 decimal digits >> 290/7
Ans = 4.1429e+001
format long e Scientific notation >> format long e
with 15 decimal digits >> 290/7
Ans = 4.142857142857143e+001
format short g Best of 5-digit fixed >> format short g
or floating point >> 290/7
Ans = 41.429
format long g Best of 15-digit fixed >> format long g
or floating point >> 290/7
Ans = 41.4285714285714
format bank Two decimal digits >> format bank
>> 290/7
Ans = 41.43
Using the sqrt built-in function

>> sqrt(64) ← Argument is a number


ans = 8

>> sqrt(50+14*3) ← Argument is an expression


ans = 9.5917

>> sqrt(54+9*sqrt(100)) ← Argument includes a function


ans = 12

>> (15+600/4)/sqrt(121) ← function is included in an expression


ans = 15
Elementary math functions

cos(x) - Cosine abs(x) Absolute value

sin(x) - Sine sign(x) - Signum function

tan(x) - Tangent max(x) - Maximum value

acos(x) - Arc cosine min(x) - Minimum value

asin(x) - Arc sine ceil(x) - Round towards + infinite

atan(x) - Arc tangent floor(x) - Round towards - infinite

exp(x) - Exponential round(x) - Round to nearest integer

sqrt(x) - Square root rem(x,number) - Remainder after division

log(x) - Natural logarithm angle(x) - Phase angle

log10(x) - Common logarithm conj(x) - Complex conjugate


Function Description
Examples

exp(x) exponential >> exp(5)


Ans = 148.4132

sqrt(x) Square root >> sqrt(81)


Ans = 9

abs(x) absolute value >> abs(-24)


Ans = 24
log(x) Natural logarithm. >> log(1000)
Base e logarithm(ln) Ans = 6.9078
log10(x) Base 10 logarithm >> log10(1000)
Ans = 3
factorial(x) The factorial function >> factorial(5)
x! ans = 120
(x must be a positive
integer)
Finding the reminder >>rem(11,2)
rem(x,number) ans=1
of given value x.
Trigonometric math functions

Function Description Examples


sin(x) Sine of angle x ( x in >> sin(pi/6)
radians) Ans = 0.5000
sin(x) Sine of angle x ( x in >> sind(30)
Degrees) Ans = 0.5000
cos(x) Cosine of angle x ( x >> cos(pi/6)
in radians) Ans = 0.8660
tan(x) tangent of angle x (x >> tan(pi/6)
in radians) Ans = 0.5774
cot(x) cotangent of angle x >> cot(pi/6)
(x in radians) Ans = 1.7321
Rounding functions

Function Description Examples


>> round(17/5)
round(x) Round to the nearest integer
Ans = 3
>> fix(13/5)
fix(x) Round towards zero
Ans = 2
>> ceil(11/5)
ceil(x) Round towards infinity
Ans = 3
>> floor(-9/4)
floor(x) Round towards minus infinity
Ans = - 3
Returns the remainder after x >> rem(13,5)
rem(x,y)
is divided by y Ans = 3
Signum function. Returns 1 if >> sign(5)
sign(x)
x>0, -1 if x<0, and o if x=0 Ans = 1

Example: the value of the expression 𝐴 = 𝑒−𝑎 sin(𝑥) + 10√𝑦 for a = 5, x = 2,


and y = 8 is computed by
>> a = 5; x = 2; y = 8;
>> y = exp(-a)*sin(x)+10*sqrt(y)
y = 28.2904
The Assignment operator
Hierarchy of arithmetic operations

Precedence Mathematical operations

First The contents of all parentheses are evaluated first, starting


from the innermost parentheses and working outward.

Second All exponentials are evaluated, working from left to right

Third All multiplications and divisions are evaluated, working


from left to right
Fourth All additions and subtractions are evaluated, starting from
left to right

Example:

1) >> x=15 ← The number 15 assigned to the variable x


x = 15 ← MATLAB displays the variable and its assigned value

>> x=3*x - 12
← A new value is assigned to x. The new value is 3 times the previous value of
x minus 12.

Ans x = 33
>> a=12 ← Assign 12 to a
a = 12
>> b=4 ← Assign 4 to b
b=4
>> c=(a-b)+40-a/b*10 ← Assign the value of the expression on the right-hand
side to the variable c.
c =18

>> a=12; ← The variables a, b and c are defined but are not displayed since a
>> b=4; semicolon is typed at the end of each statement
>> c=(a-b)+40-a/b*10;
>> c ← The value of the variable c is displayed by typing the name of the
variable
c =18

>> a=12, b=4; c=(a-b)+40-a/b*10 ← The variable b is not displayed because


a = 12 semicolon is typed at the end of the assignment
c = 18

A variable that already exists can be reassigned a new value.


Example: >> abb=72;
>> abb=9;
>> abb
abb = 9

Once a variable is defined it can be used as an argument in functions.


Example: >> x=0.75;
>> E=sin(x)^2+cos(x)^2
E=1

Rules about variable names:


1. Can contain letters, digits, and the underscore character.
2. Must begin with a letter.
3. MATLAB is case sensitive; it distinguishes between uppercase and
lowercase letters. For examples, AA, Aa, aA and aa are the names of four
different variables.
4. Avoid using the names of a built in function for a variable i.e. sin, exp etc.

Predefined variables: i.e. pi, esp, inf, I or j.

Show that at x=π/5.


Solution: x = pi/5;

>> LHS=cos(x/2)^2
LHS = 0.9045

>> RHS=(tan(x)+sin(x))/(2*tan(x))
RHS = 0.9045
Creating Vectors
A vector is a one-dimensional array of numbers. MATLAB allows creating two
types of vectors:
Row vectors
Column vectors
Variable name=[ type vector element]
Row vector: To create a row vector type the elements with a space or a comma
between the elements inside the square brackets.
Column vector: To create a column vector type the left square bracket [ and
then enter the elements with a semicolon between them, or press the Enter key
after each element. Type the right square bracket ] after the last element.

Row vectors are created by enclosing the set of elements in square brackets,
using space or comma to delimit the elements.

For example,
r = [7 8 9 10 11]

MATLAB will execute the above statement and return the following result:
r=
Columns 1 through 4
7 8 9 10
Column 5
11

Another example

r = [7 8 9 10 11];
t = [2, 3, 4, 5, 6];
res = r + t
MATLAB will execute the above statement and return the following result:
res =
Columns 1 through 4
9 11 13 15
Column 5
17

Column vectors are created by enclosing the set of elements in square brackets,
using semicolon (;) to delimit the elements.

c = [7; 8; 9; 10; 11]

MATLAB will execute the above statement and return the following result:
c=
7
8
9
10
11
Creating a vector with constant spacing by specifying the first term, the spacing,
and the last term
Variable_name= [m:q:n] or variable_name= m:q:n
Examples :
>> x=[1:2:13] First element 1, spacing 2, last element 13
x=
1 3 5 7 9 11 13
>> y=[1.5:0.1:2.1] First element 1.5, spacing 0.1, last element 2.1
y=
1.5000 1.6000 1.7000 1.8000 1.9000 2.0000 2.1000

>> z=[-3:7] First element -3, last element 7. If spacing is omitted, the
default is 1
z=
-3 -2 -1 0 1 2 3 4 5 6 7

>> xa=[21:-3:6] First element 21, spacing -3, last element 6


xa =
21 18 15 12 9 6

Creating a vector with constant spacing by specifying the first and last terms and
the number of terms
Variable_name=linspace(xi,xf,n)
Examples :
>> va= linspace(0,8,6) 6 elements, first element 0, last element 8
va = 0 1.6000 3.2000 4.8000 6.4000 8.0000

>> vb= linspace(30,10,11) 11 elements, first element 30, last element


10
vb = 30 28 26 24 22 20 18 16 14 12 10
>> u=linspace(49.5,0.5) when the number of elements is omitted, the default
is 100
>> b=[7 2 76 33 8 The enter key is pressed a new line is entered
u = Columns 1 through
1 98 6 25 6 9
49.50 1 48.5101 48.0152 47.5202 47.0253 46.5303 46.0354
00 49.005
5 54 68 9 0]
45.5404
Ans
……………
Columns 91 through 99
4.9545 4.4596 3.9646 3.4697 2.9747 2.4798 1.9848 1.4899
0.9949
Column 100
0.5000

Creating a Two-dimensional array (matrix)


In MATLAB, a matrix is created by entering each row as a sequence of space or
comma separated elements, and end of a row is demarcated by a semicolon. For
example, let us create a 3-by-3 matrix as:
>> m = [1 2 3; 4 5 6; 7 8 9]

MATLAB will execute the above statement and return the following result:
m=
1 2 3
4 5 6
7 8 9
>> cd=6; e=3; h=4; Three variables are defined
>> mat=[e, cd*h, cos(pi/3); h^2, sqrt(h*h/cd), 14]
Elements are defined by Mathematical expressions
mat =
3.0000 24.0000 0.5000
16.0000 1.6330 14.0000

1 3 5 7 9 11
0 5 10 15 20 25
10 20 30 40 50 60
67 2 43 68 4 13
The zeros, ones and eye Commands
The zeros(m,n) and the ones(m,n) commands create a matrix with m rows and n
columns, in which all the elements are the numbers o and 1 respectively. The
eye(n) command creates a square matrix with n rows and n columns in which the
diagonal elements are equal to 1, and the rest of the elements are 0. This matrix
is called the identity matrix. Examples are:
>> zr=zeros(3,4) >> a=zeros(4) >> ne=ones(4,3)
zr = a= ne =
0 0 0 0 0 0 0 0 1 1 1
0 0 0 0 0 0 0 0 1 1 1
0 0 0 0 0 0 0 0 1 1 1
0 0 0 0 1 1 1

>> idn=eye(5)
idn =
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1

The Transpose Operator


The transpose operator is applied by typing a single quote ‘ following the
variable to be transposed.
Examples are:
>> aa=[3 8 1] Define a row vector aa
aa =
3 8 1

>> bb=aa‘ Define a row vector bb as the transpose of vector aa


bb =
3
8
1

>> D=C' Define a matrix D as the transpose of matrix C


D=
2 21 41
55 5 64
14 32 9
8 11 1

Array Addressing Vector:


>> S=[35 46 78 23 5 14 81 3 55] Define a vector
S=
35 46 78 23 5 14 81 3 55

>> S(4) Display the fourth element


ans =
23

>> S(6)=273 Assign a new value to the sixth element


S=
35 46 78 23 5 273 81 3 55

>> S(2)+S(8) Use the vector elements in mathematical expressions


ans = 49

>> S(5)^S(8)+sqrt(S(7)) Use the vector elements in mathematical


expressions
ans = 134

Matrix operations
>> A=[3 11 6 5; 4 7 10 2; 13 9 0 8] Create a 3x4 matrix
A=
3 11 6 5
4 7 10 2
13 9 0 8

>> A(3,1)=20 Assign a new value to the (3,1) element


A=
3 11 6 5
4 7 10 2
20 9 0 8

>> A(2,4)-A(1,2) Use elements in a mathematical expression


ans = -9

Using Colon : in addressing Arrays


>> v=[4 15 8 12 34 2 50 23 11] A vector v is created
v=
4 15 8 12 34 2 50 23 11

>> u=v(3:7) A vector u is created from the elements 3 through 7 of vector v


u=
8 12 34 2 50 A vector u is created from the elements 3
through 7 of vectors v

For a matrix
A(:,n) Refers to the elements in all the rows of column n of the matrix A
A(n,: ) Refers to the elements in all the columns of row n of the matrix A
A(:,m:n) Refers to the elements in all the rows between columns m and n of
the matrix A
A(m:n,:) Refers to the elements in all the columns between rows m and n of
the matrix A
A(m:n,p:q) Refers to the elements in rows m through n and columns p through
q of the matrix A
Examples
>> A=[1 3 5 7 9 11; 2 4 6 8 10 12; 3 6 9 12 15 18; 4 8 12 16 20 24;
5 10 15 20 25 30]
A=
1 3 5 7 9 11
2 4 6 8 10 12
3 6 9 12 15 18
4 8 12 16 20 24
5 10 15 20 25 30
Using a colon in addressing arrays
Examples:

>> B=A(:,3) Define a column vector B from the elements in all the rows of
column 3 in Matrix A
B=
5
6
9
12
15
>> C=A(2,:) Define a row vector C from the elements in all the columns
of row 2 in matrix A
C=
2 4 6 8 10 12

>> E=A(2:4,:) Define a matrix E from the elements in rows 2 through 4


and all the columns in matrix A
E=
2 4 6 8 10 12
3 6 9 12 15 18
4 8 12 16 20 24

>> F=A(1:3,2:4) Create a matrix f from the elements in rows 1 through 3 and
columns 2 through 4 In matrix A
F=
3 5 7
4 6 8
6 9 12

>> V=4:3:34 Create a vector V with 11 elements


V=
4 7 10 13 16 19 22 25 28 31 34

>> u=V([3,5,7:10]) Create a vector u from the 3rd, the 5th, and 7th through
10 elements of V
u=
10 16 22 25 28 31
>> B=[5 7 2] Define vector B with 3 elements
B=
5 7 2

>> B(8)=4 Assign a value to the 8th element


B=
5 7 2 0 0 0 0 4
(MATLAB assigns zeros to the 4th through 7th elements )

>> P(5)=24
P=
0 0 0 0 24

>> A=[3 8 1 24] Define vector A with 4 elements


A=
3 8 1 24
>> B=4:3:16 Define vector B with 5 elements
B=
4 7 10 13 16
>> C=[A B] Define a new vector C by appending A and B
C=
3 8 1 24 4 7 10 13 16
>> D=[A';B'] Create a new column vector D by appending A’ and B’
D=
3
8
1
24
4
7
10

>> A=[1 2 3 4; 5 6 7 8] Define a 2 x 4 matrix


A=
1 2 3 4
5 6 7 8

>> A(3,:)=[10:4:22] Add the vector 10 14 18 22 as the third row of A


A=
1 2 3 4
5 6 7 8
10 14 18 22

>> B=eye(3)
B=
1 0 0
0 1 0
0 0 1

C=[A B] Append the matrix B to matrix A. The number of rows in B and A


must be the same
C=
1 2 3 4 1 0 0
5 6 7 8 0 1 0
10 14 18 22 0 0 1
>> A=[3 6 9; 8 5 11]
A=
3 6 9
8 5 11
>> A(4,5) =17 Assign a value to the (4,5) element

A=
3 6 9 0 0 MATLAB changes the matrix size to 4X5, and
8 5 11 0 0 assigns zeros to the new elements
0 0 0 0 0
0 0 0 0 17

>> Q(3,4)=15 Assign a value to the (3,4) element of a new matrix


Q=
0 0 0 0
0 0 0 0
0 0 0 15

Deleting Elements
>> kt=[2 8 40 3 55 23 15 75 80] Define a vector with 10 elements
kt =
2 8 40 3 55 23 15 75 80
>> kt(6)=[ ] Eliminate the sixth element
kt =
2 8 40 3 55 15 75 80
>> kt(3:6)=[ ] Eliminate elements 3 through 6
kt =
2 8 75 80
>> mtr=[5 78 4 24 9; 4 0 36 60 12; 56 13 5 89 31] Define 3x5 matrix
mtr =
5 78 4 24 9
4 0 36 60 12
56 13 5 89 31
>> mtr(:,2:4)=[ ] Eliminate all the rows of columns 2 through 4
mtr =
5 9
4 12
56 31

Built-in-functions for handling arrays

Function Description Examples


Returns the number of >> A=[5 9 2 4];
length(A) elements >> length(A)
In the vector A ans = 4
>> A=[6 1 4 0 12; 5 19 6 8 2]
A=
Returns a row vector [m,n], 6 1 4 0 12
Size(A) where m and n are the size 5 19 6 8 2
m x n of the array A >> size(A)
ans =
2 5
Rearrange a matrix A that has >> A=[5 1 6; 8 0 2]
Reshape(A,m,n) r rows and s columns to have A =
m rows and n columns. R 5 1 6
times s must be equal to m 8 0 2
times n >> B=reshape(A,3,2)
=
5 0
8 6
1 2
>> v=[7 4 2];
>> A=diag(v)
When v is a vector, creates a
A=
diag(v) square matrix with the
7 0 0
elements of v in the diagonal
0 4 0
0 0 2
>> A=[1 2 3; 4 5 6; 7 8 9]
A=
1 2 3
4 5 6
When A is a matrix, creates a
7 8 9
diag(A) vector from the diagonal
>> vec=diag(A)
elements of A
vec =
1
5
9

Mathematical Operations with Arrays


>> A=[5 -3 8; 9 2 10]
A=
5 -3 8 Define two 2X3 matrices A and B
9 2 10
>> B=[10 7 4; -11 15 1]
B=
10 7 4
-11 15 1
>> A-B ← Subtracting matrix B from matrix A
ans =
-5 -10 4
20 -13 9
>> C=A+B ← Define a matrix C that is equal to A + B
C=
15 4 12
-2 17 11
>> C-8 ← The number 8 is subtracted from the matrix C
ans =
7 -4 4
-10 9 3

>> A=[1 4 2; 5 7 3; 9 1 6; 4 2 8] ← Define a 4X3 matrix A


A=
1 4 2
5 7 3
9 1 6
4 2 8

>> B=[6 1; 2 5; 7 3] ← Define a 3X2 matrix B


B=
6 1
2 5
7 3
>> C=A*B ← Multiply matrix A by matrix B and assign the result to
variable C
C=
28 27
65 49
98 32
84 38
>> D=B*A ← Trying to multiply B by A, B*A, gives an error since the
number of columns in B is 2 and the number of rows in A is 4
??? Error using ==> *
Inner matrix dimensions must agree.

>> F=[1 3; 5 7]
F=
1 3 Define two 2 X 2 matrices F and G
5 7
>> G=[4 2; 1 6]
G=
4 2
1 6
>> F*G ← Multiply F*G
ans =
7 20
27 52
>> G*F ← Multiply G*F
ans =
14 26
31 45
Note: The answer of F*G is not the same as the answer G*F

>> AV=[2 5 1] ← Define a three-element column vector AV


AV =
2 5 1
>> BV=[3; 1; 4] ← Define a three-element column vector BV
BV =
3
1
4
>> AV*BV ← Multiply AV by BV. The answer is a scalar. (dot product of
two vectors)
ans =
15
>> BV*AV ← Multiply AV by BV. The answer is a 3 X 3 matrix
ans =
6 15 3
2 5 1
8 20 4

>> A=[2 5 7 0; 10 1 3 4; 6 2 11 5] ← Define a 3 X 4 matrix A


A=
2 5 7 0
10 1 3 4
6 2 11 5

>> b=3← Assign the number 3 to the variable b


b=
3
>> b*A ← Multiply the matrix A by b. This can be done by either typing
b*A or A*b
ans =
6 15 21 0
30 3 9 12
18 6 33 15

>> A*b
ans =
6 15 21 0
30 3 9 12
18 6 33 15

>> C=A*5 ← Multiply the matrix A by 5 and assign the result to a new
variable C
C=
10 25 35 0
50 5 15 20
30 10 55 25

>>C= 5*A
C=
10 25 35 0
50 5 15 20
30 10 55 25
Inverse of the Matrix
>> A=[7 3 8; 4 11 5; 6 7 10] >> A=[2 1 4; 4 1 8; 2 -1 3] ← Creating the
A= matrix A
7 3 8 A=
4 11 5 2 1 4
6 7 10 4 1 8
>> I=eye(3) 2 -1 3
I= >> B=inv(A) ← Use the inv function to
1 0 0 find the inverse of A and assign it to B
0 1 0 B=
0 0 1 5.5000 -3.5000 2.0000
>> A*I 2.0000 -1.0000 0
ans = -3.0000 2.0000 -1.0000
7 3 8
4 11 5
6 7 10
>> I*A
ans =
7 3 8
4 11 5
6 7 10

Use matrix operations to solve the following system of linear equations


Solution: Using the rules of linear algebra, the above system of equations can be
written in the matrix form A X = B or in the form X C = D:
The solution of both forms is shown below:
>> A=[4 -2 6; 2 8 2; 6 10 3]; ← Solving the form A X = B
>> B=[8; 4; 0];
>> X=A\B ← Solving by using left division X = A \ B
X=
-1.8049
0.2927
2.6341

>> Xb= inv(A)*B ← Solving by using the inverse of A ( i.e. X= B)

Xb =
-1.8049
0.2927
2.6341
>> C=[4 2 6; -2 8 10; 6 2 3]; ← Solving the form X C = D
>> D=[8 4 0];
>> Xc= D/C ← Solving by using right division X= D / C
Xc =
-1.8049 0.2927 2.6341

>> Xd=D*inv(C) ← Solving by using the inverse of C, X=D.


Xd =
-1.8049 0.2927 2.6341
The M Files
MATLAB allows writing two kinds of program files:
Scripts - script files are program files with .m extension. In these files, you
write series of commands, which you want to execute together. Scripts do not
accept inputs and do not return any outputs. They operate on data in the
workspace.
Functions - functions files are also program files with .m extension. Functions
can accept inputs and return outputs. Internal variables are local to the function.
You can use the MATLAB editor or any other text editor to create your .m files.
In this section, we will discuss the script files. A script file contains multiple
sequential lines of MATLAB commands and function calls. You can run a script
by typing its name at the command line

To create scripts files, you need to use a text editor. You can open the MATLAB
editor in two ways:
 Using the command prompt
 Using the IDE

If you are using the command prompt, type edit in the command prompt. This
will open the editor. You can directly type edit and then the filename (with .m
extension)
edit
Or
edit <filename>
Alternatively, if you are using the IDE, choose NEW -> Script. This also opens
the editor and creates a file named Untitled. You can name and save the file after
typing the code.

Type the following code in the editor:


No of Students = 6000;
Teaching Staff = 150;
Non Teaching Staff = 20;
Total = No of Students + Teaching Staff ...
+ Non Teaching Staff;
disp(Total);

After creating and saving the file, you can run it in two ways:

 Clicking the Run button on the editor window or


 Just typing the filename (without extension) in the command prompt: >>
prog1
The command window prompt displays the result:
6170

Example 1
Create a script file, and type the following code:
a = 5; b = 7;
c=a+b
d = c + sin(b)
e=5*d
f = exp(-d)

When the above code is compiled and executed, it produces the following result:

c = 12
d = 12.6570
e = 63.2849
f = 3.1852e-06

Example 2
Create a script file with the following code:

str = 'Hello World!'


n = 2345
d = double(n)
un = uint32(789.50)
rn = 5678.92347
c = int32(rn)
When the above code is compiled and executed, it produces the following result:

=
Hello World!
n=
2345
d=
2345
un =
790
rn =
5.6789e+03
c=
5679

Example 3

The following examples show the use of arithmetic operators on scalar data.
Create a script file with the following code:
a = 10;
b = 20;
c=a+b
d=a-b
e=a*b
f=a/b
g=a\b
x = 7;
y = 3;
z=x^y

When you run the file, it produces the following result:

c = 30
d = -10
e = 200
f = 0.5000
g=2
z = 343

Example 4
Create a script file and type the following code:

a = 100;
b = 200;
if (a >= b)
max = a
else
max = b
end

When you run the file, it produces following result:

max = 200

Flow control (Loops)


There may be a situation when you need to execute a block of code several
times. In general, statements are executed sequentially. The first statement in a
function is executed first, followed by the second, and so on.
Programming languages provide various control structures that allow for more
complicated execution paths.
A loop statement allows us to execute a statement or group of statements
multiple times. The drawing shows the general form of a loop statement for most
programming languages.
Matlab provides various types of loops to handle looping requirements
including: while loops, for loops, and nested loops. If you are trying to declare
or write your own loops, you need to make sure that the loops are written as
scripts and not directly in the Command Window.
To start a new script, locate the button in the upper left corner of the window
labeled New Script.

MAT LAB has five flow control statements

 If statement
 Switch statement
 For loops
 While loops
 Break statements

MATLAB provides following types of loops to handle looping requirements

Loop Description
Type

while loop Repeats a statement or group


of statements while a given
condition is true. It tests the
condition before executing the
loop body.
for loop Executes a sequence of
statements multiple times and
abbreviates the code that
manages the loop variable.
nested You can use one or more loops
loops inside any another loop.
break Terminates the loop statement
statement and transfers execution to the
statement immediately
following the loop.

Decision making Structures


Decision making structures require that the programmer should specify one or
more conditions to be evaluated or tested by the program, along with a statement
or statements to be executed if the condition is determined to be true, and
optionally, other statements to be executed if the condition is determined to be
false.
Following is the general form of a typical decision making structure found in
most of the programming languages:

MATLAB provides following types of decision making statements.

if ... end statement An if ... end statement consists of a boolean expression


followed by one or more statements.
if...else...end statement An if statement can be followed by an optional else
statement, which executes when the boolean
expression is false.
If... An if statement can be followed by one (or more)
elseif...elseif...else...end optional elseif... and an else statement, which is very
statements useful to test various conditions.
nested if statements You can use one if or elseif statement inside another if
or elseif statement(s).
switch statement A switch statement allows a variable to be tested for
equality against a list of values.
nested switch You can use one switch statement inside another
statements switch statement(s).

if….end Statement
An if ... end statement consists of an if statement and a boolean expression
followed by one or more statements. It is delimited by the end statement.

Syntax
The syntax of an if statement in MATLAB is:

if <expression>
% statement(s) will execute if the boolean expression is true
<statements>
end
If the expression evaluates to true, then the block of code inside the if statement
will be executed. If the expression evaluates to false, then the first set of code
after the end statement will be executed.

Example

Create a script file and type the following code:

a = 10;
% check the condition using if statement
if a < 20
% if condition is true then print the following
fprintf('a is less than 20\n' );
end
fprintf('value of a is : %d\n', a);
When you run the file, it displays the following result:
a is less than 20
value of a is : 10

if...else...end Statement
An if statement can be followed by an optional else statement, which executes
when the expression is false.
Syntax
The syntax of an if...else statement in MATLAB is:

if <expression>
% statement(s) will execute if the boolean expression is true
<statement(s)>
else
<statement(s)>
% statement(s) will execute if the boolean expression is false
end

If the boolean expression evaluates to true, then the if block of code will be
executed, otherwise else block of code will be executed.
Example
Create a script file and type the following code:

a = 100;
% check the boolean condition
if a < 20
% if condition is true then print the following
fprintf('a is less than 20\n' );
else
% if condition is false then print the following
fprintf('a is not less than 20\n' );
end
fprintf('value of a is : %d\n', a);

When the above code is compiled and executed, it produces the following result:

a is not less than 20


value of a is : 100

if...elseif...elseif...else...end Statements

An if statement can be followed by one (or more) optional elseif... and an else
statement, which is very useful to test various conditions.
When using if... elseif...else statements, there are few points to keep in mind:
An if can have zero or one else's and it must come after any elseif's.
An if can have zero to many elseif's and they must come before the else.
Once an else if succeeds, none of the remaining elseif's or else's will be tested.

Syntax
if <expression 1>
% Executes when the expression 1 is true
<statement(s)>
elseif <expression 2>
% Executes when the boolean expression 2 is true
<statement(s)>
Elseif <expression 3>
% Executes when the boolean expression 3 is true
<statement(s)>
else
% executes when the none of the above condition is true
<statement(s)>
end

Example
Create a script file and type the following code in it:
a = 100;
% check the boolean condition
if a = = 10
% if condition is true then print the following
fprintf('Value of a is 10\n' );
elseif ( a = = 20 )
% if else if condition is true
fprintf ('Value of a is 20\n' );
elseif a = = 30
% if else if condition is true
fprintf('Value of a is 30\n' );
else
% if none of the conditions is true '
fprintf('None of the values are matching\n');
fprintf('Exact value of a is: %d\n', a );
end

When the above code is compiled and executed, it produces the following result:

None of the values are matching


Exact value of a is: 100

The Nested if Statements

It is always legal in MATLAB to nest if-else statements which means you can
use one if or elseif statement inside another if or elseif statement(s).
Syntax
The syntax for a nested if statement is as follows:

if <expression 1>
% Executes when the boolean expression 1 is true
if <expression 2>
% Executes when the boolean expression 2 is true
end
end

You can nest elseif...else in the similar way as you have nested if statement.
Example
Create a script file and type the following code in it:
a = 100;
b = 200;
% check the boolean condition
if( a == 100 )
% if condition is true then check the following
if( b == 200 )
% if condition is true then print the following
fprintf('Value of a is 100 and b is 200\n' );
end
end
fprintf('Exact value of a is : %d\n', a );
fprintf('Exact value of b is : %d\n', b );

When you run the file, it displays:


Value of a is 100 and b is 200
Exact value of a is : 100
Exact value of b is : 200

While Loop

The while loop repeatedly executes statements while a specified condition is


true.
The syntax of a while loop in MATLAB is as following:

while <expression>
<statements>
end

The while loop repeatedly executes a program statement(s) as long as the


expression remains true.

An expression is true when the result is nonempty and contains all nonzero
elements (logical or real numeric). Otherwise, the expression is false.

Example:1

a = 10; % while loop execution


while( a < 20 )
fprintf('value of a: %d\n', a);
a = a + 1;
end

When the code above is executed, the result will be:

value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19

Example 2:

x=3
while (x<100)
x=x*3;
end

When the code above is executed, the result will be:


Output

x=243

Remark: one can think of while loop as a combination of for loop and an if
statement. Here, the looping will keep going indefinitely as long as the
condition (x<100), is satisfied. Therefore, the value of x progresses from
3,9,27,81, to 243 when loop is terminated.

Example 3:

x = input(‘Enter a Number:’);
count = 0;
while x > 1
x = x/2;
count = count + 1;
end
display (count);

When the code above is executed, the result will be:

Enter a Number:
130
Count =
8
Example : 4

x = input(‘Enter an integer:’);
Fact = 1;
While x > 1;
Fact = fact * x;
End
Display(fact);

When the code above is executed, the result will be:

Enter a Integer:
12
Fact =
479001600

For loop

A for loop is a repetition control structure that allows you to efficiently write a
loop that needs to execute a specific number of times.

The syntax of a for loop in MATLAB is as following:

for index = values


<program statements>
...
end
Example: 1

b=3
for k = 1:5
b = b^k
end

When the code above is executed, the result will be:

Output
3
9
27
81
243

Remark: the outputs are 3^1,3^2,3^3,3^4 and 3^5. The value of “k” keeps
changing as we go through the loop.

Example: 2

sum1 = 0;
for k = 1:9
sum1 = sum1+ k;
end

When the code above is executed, the result will be:


Output
45

Remark: this program performs the summation of 1+2+3+4+5+6+7+8+9 =


45

Example: 3

sum1 = 0;
for k = 1:2:9
sum1 = sum1+ k;
end
sum1

When the code above is executed, the result will be:

Output
25

Remark: this program performs the summation of 1+3+5+9 = 45. This


command “for k = 1:2:9” means we go through the loop only 5 times. First
time with k=1, second time with k=1+2(=3), third time with k = 1+2+2(=5),
and so on. The looping stops once k reaches 9.

Example: 4 using array


b = [3 8 9 4 7 5];
sum1 = 0;
for k = 1:4
sum1 = sum1+ b(k);
end
sum1

When the code above is executed, the result will be:

Output
24

Remark: this program performs the summation of sum1=


b(1)+b(2)+b(3)+b(4) = 3+8+9+4 = 24

Example: 5 using array with step 2

b = [3 8 9 4 7 5];
sum1 = 0;
for k = 1:2:5
sum1 = sum1+ b(k);
end
sum1

When the code above is executed, the result will be:

Output
19

Remark: this program performs the summation of sum1= b(1)+b(3)+b(5) =


3+9+7 = 19

Example: 6

for a = 10:20
fprintf(‘value of a:%d\n’,a);
end

When the code above is executed, the result will be:

Output
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
value of a: 20

Example: 7 using two for loops


sum1 = 0;
for n = 1:2
for m = 1:3
sum1 = sum1+ n * m;
end
end
sum1
When the code above is executed, the result will be:

Output
18

Remark: this program performs the summation of sum1=


1*1+1*2+1*3+2*1+2*2+2*3 = 18

Example: 8 using two for loops with printf

for n = 1:2
for m = 1:3
fprintf(‘n = %3u m = %3u \r’, n, m)
end
end
When the code above is executed, the result will be:

Output
n=1 m=1
n=1 m=1
n=1 m=1
n=2 m=2
n=2 m=2
n=2 m=2

Example: 9 More complicated use of loop and index

b = [3 5 7 4 9 8 3];
c = [2 3 5 7];
sum1 = 0;
for k = 1:4
sum1 = sum1+ b (c(k));
end
sum1

When the code above is executed, the result will be :

Output
24

Remark: this program performs the summation of


sum1= b(c(1)) + b(c(2)) + b(c(3)) + b(c(4))
= b(2) + b(3) + b(5) + b(7)
= 5+7+9+3
= 24
Lab Program – 3&4

Numerical methods and their applications: Curve fitting: Straight line fit,
Polynomial fit

MATLAB has an excellent set of graphic tools. Plotting a given data set or the
results of computation is possible with very few commands. You are highly
encouraged to plot mathematical functions and results of analysis as often as
possible. Trying to understand mathematical equations with graphics is an
enjoyable and very efficient way of learning mathematics. Being able to plot
mathematical functions and data freely is the most important step, and this
section is written to assist you to do just that.
Creating simple plots

The basic MATLAB graphing procedure, for example in 2D, is to take a vector
of x- coordinates, x = (x1; : : : ; xN), and a vector of y-coordinates, y = (y1; : : :
; yN), locate the points (xi; yi), with i = 1; 2; : : : ; n and then join them by
straight lines. You need to prepare x and y in an identical array form; namely, x
and y are both row arrays and column arrays of the same length.
Example:1
Plot a graph considering the vectors, x = (1; 2; 3; 4; 5; 6) and y = (3; -1; 2; 4; 5;
1)
>> x = [1 2 3 4 5 6];
>> y = [3 -1 2 4 5 1];
>> plot(x,y)

Note: The plot functions have different forms depending on the input arguments.
If y is a vector plot(y) produces a piecewise linear graph of the elements of y
versus the index of the elements of y. If we specify two vectors, as mentioned
above, plot(x,y) produces a graph of y versus x.

Example: 2
Create x as a vector of linearly spaced values between 0 and 2π. Use an
increment of π/100 between the values. Create y as sine values of x. Create a line
plot of the data.

x = 0:pi/100:2*pi;
y = sin(x);
>> xlabel('x = 0:2\pi')
>> ylabel('Sine of x')
>> title('Plot of the Sine function')
>>plot(x,y)
Multiple data sets in one plot
Multiple (x; y) pairs arguments create multiple graphs with a single call to plot.

For example, these statements plot three related functions of x: y1 = 2 cos(x),


y2 = cos(x), and y3 = 0:5* cos(x), in the interval 0 ≤ x ≤ 2π

>> x = 0:pi/100:2*pi;
>> y1 = 2*cos(x);
>> y2 = cos(x);
>> y3 = 0.5*cos(x);
>> plot(x,y1,'--',x,y2,'-',x,y3,':')
>> xlabel('0 \leq x \leq 2\pi')
>> ylabel('Cosine functions')
>>
legend('2*cos(x)','cos(x)','0.5*co
s(x)'
)
>> title('Typical example of
multipleplots')
>> axis([0 2*pi -3 3])
The result of multiple data sets in one graph plot is shown in Figure.

Example
Define x as 100 linearly spaced values between −2π and 2π. Define y1 and y2 as
sine and cosine values of x. Create a line plot of both sets of data.

x = linspace(-2*pi,2*pi);
y1 = sin(x);
y2 = cos(x);
plot(x,y1,x,y2)
Three Curves in single Plot

Plot three sine curves with a small phase shift between each line. Use the default
line style for the first line. Specify a dashed line style for the second line and a
dotted line style for the third line.

x = 0:pi/100:2*pi;
y1 = sin(x);
y2 = sin(x-0.25);
y3 = sin(x-0.5);

%figure
plot(x,y1,x,y2,'--',x,y3,':')

Specify Line Style, Color, and Marker

Plot three sine curves with a small phase shift between each line. Use a green
line with no markers for the first sine curve. Use a blue dashed line with circle
markers for the second sine curve. Use only cyan star markers for the third sine
curve
x = 0:pi/10:2*pi;
y1 = sin(x);
y2 = sin(x-0.25);
y3 = sin(x-0.5);
plot(x,y1,'g',x,y2,'b--o',x,y3,'c*')

Bifurcation Plots

x = linspace(0,3);
y1 = sin(5*x);
y2 = sin(15*x);
subplot(2,1,1);
plot(x,y1)
title('Top Plot')
ylabel('sin(5x)')
subplot(2,1,2);
plot(x,y2)
title('Bottom Plot')
ylabel('sin(15x)')

Subplots

x = linspace(0,6);
subplot(2,2,1); % plot sine function
plot(x,sin(x));
subplot(2,2,2); % plot cosine function
plot(x,cos(x));
subplot(2,2,3); % plot negative exponential function
plot(x,exp(-x));
subplot(2,2,4); % plot x^3
plot(x, x.^3);

Plots Circle
r = 2;
xc = 4;
yc = 3;
theta =
linspace(0,2*pi);
x = r*cos(theta) + xc;
y = r*sin(theta) + yc;
plot(x,y) axis equal

Plotting in 3-D

[x,y] = meshgrid([-2:.2:2]); % set up 2-D plane


Z = x.*exp(-x.^2-y.^2); % plot 3rd dimension on plane figure
surf(x,y,Z,gradient(Z)) % surface plot, with gradient(Z)
% determining color distribution
colorbar % display color scale, can adjust
% location similarly to legend
Polynomials in MATLAB
Evaluating Polynomials
p = [1 7 0 -5 9];
polyval (p,4)
Ans = 693

p = [1 7 0 -5 9];
X = [1 2 -3 4; 2 -5 6 3; 3 1 0 2; 5 -7 3 8];
polyvalm(p, X)

ans=
2307 -1769 -939 4499

2314 -2376 -249 4695


2256 -1892 -549 4310

Finding the roots of Polynomials


Solve the equation 3𝑥2 − 2𝑥 − 4
Create the vector to represent the polynomial, then find the roots
P=[3 -2 -4];
r = roots (p)
Ans r = 2 x 1
1.532
-0.8685

Solve the equation 𝑥4 + 7𝑥3 − 5𝑥 + 9 = 0


Create a vector to represent the polynomial, then find the roots
p = [1 7 0 -5 9];
r = roots(p)
r=
-6.8661 + 0.0000i
-1.4247 + 0.0000i
0.6454 + 0.7095i
0.6454 - 0.7095i

The function poly is an inverse of the roots function and returns to the
polynomial coefficients. For example:
p2 = poly(r)

p2 =
Columns 1 through 3:
1.00000 + 0.00000i 7.00000 + 0.00000i 0.00000 + 0.00000i
Columns 4 and 5:
-5.00000 - 0.00000i 9.00000 + 0.00000i

Polynomial Curve Fitting


The polyfit function finds the coefficients of a polynomial that fits a set of data
in a least-squares sense. If x and y are two vectors containing the x and y data to
be fitted to a n-degree polynomial, then we get the polynomial fitting the data by
writing p = polyfit(x,y,n)

Lab-Program 3: Numerical methods and their applications: Curve


fitting: Straight line fit.
By rhe method of least squares, fit a straight fine to th fi ll .
e O owmg data:

x: I 2 3 4 5
y: 14 13 9 5 2

Here 11=5 values of (x, y) are given. We first fonn the following Table.
1

n
'Hercand in expressions that follow, E denotes L·
i=I
'Nt1etha1La= a+ a+ a ... (11 terms)= na

,_ )
.r; y;
14 I
I
13 4 i6
2
9 9 27
3
4 5 16 20
5 2 25 10

X; =J5 L Yi= 43 L x; = 55 L x,y, = n j

From lhc deta•,Is ava1•1able in the Table, we find that the normal cquaiio
the line of bcsl fit are•

43 = 5a + 15b,
97 = 15a + 55b.

Solving these equations, we get a = 91 /5 and b = - (16/5). Hence,for'


line of best fit is
Lab Program -3 code with degree1 for strainght
line

Program with degree 2


Lab Program 4: Program code with degree2 polynomial curve fit
Lab Program - 5
Numerical Integration and Differentiation: Trapezoidal method,Simpson
method.
Lab Program 5-Numerical Integration and Differentiation: Trapezoidal method.

Program Code With Example 1:f=1/(1+x)

OUTPUT
Enter lower limit, a:1
Enter upper limit, b:2
Enter no. of subintervals, n: 5
The approximate value of integral by Trapizoidal Rule is: 0.40592741
Program with Example 2:f=sin(x)

OUTPUT
Enter lower limit, a:2
Enter upper limit, b:8
Enter no. of subintervals, n: 5
The approximate value of integral by Trapizoidal Rule is: -0.23736200
Lab Program 6-Numerical Integration and Differentiation:Simpson’s method
Simpson’s 1/3 rule
Program Code Example 1 : SIMPSON 1/3 RULE FOR cos(x)-log(x)+exp(x)
OUTPUT
Enter lower limit a:0
a =0

Enter upper limit b:10


b =10

Enter the no. of subinterval:5


n =5

Please enter valid n!!!


Enter n as even number6
n =6

The approximation value of integral by Simsons 1/3 Rule is: Inf

Program code Example 2: SIMPSON 1/3 RULE FOR 1/(1+X)


OUTPUT
Enter lower limit a:0
a =0

Enter upper limit b:10


b =10

Enter the no. of subinterval:6


n =6

The approximation value of integral by Simsons 1/3 Rule is: 2.4492


Program code Example 3: SIMPSON 1/3 RULE FOR log(x)
Output:

simsons1
Enter lower limit a:4
a =4

Enter upper limit b:5.2


b =5.2000

Enter the no. of subinterval:6


n =6

The approximation value of integral by Simsons 1/3 Rule is:


1.8278
Program Code for Simson’s 3/8 Rule

Lab Program 7&8


Linear and Nonlinear Equations: Eigen values, Eigen vectors, Solution of linear
algebraic equations using Gauss Elimination and LU decomposition, Solution of
nonlinear equation in single variable using Gauss-Siedal and Newton-Raphson
method.
Eigen Values and Eigen Vectors:
- -.'.?.,&
q 3, - -:j- ..,..,. +-:•]\ +'3' -:: 0
-") >t"?:> - "1- :;a,. "2.b o --• f-'n)
A -:::.-2.,. I ['X:) L-')_ _ ,--')4(-l-)1.- ' 0
...;,.) - i - ,l..'& l, 0 .) lJ =. tJ

l ) -o

€) ,.._ - t )", • I :>.-. -+ -:: O


· ,_..., l ;)._) -
c:,,:.\ c),. ,,;t 1{). -ra ) ,,o
(). t ):. 0•.1 - ·' 'T g_) ;all ..J

=-)
-"I :>'I
,-,.(),-,)
I I - f)

-
::) )? -
---
r-,...-,,;
(:. 'J-'.
o -,l o
) ( --t ".l.) ( ,-.- ) (') -t") :.D
--.. \\;'.; QA . d
'?
,. = -· ,, ,,6 'J
o.)-1:" t'-v.. A
f-Y ,i,.:;_ iot e •y 'Y'>l'\ON1'

(1-) t -1 ,i;_-n

r(-->i)tl -1, r
ll1'ij1 (\- ::r_-,ll

c c c;)
..
2... ..,,')
1.'{ ,,_ o · · Nil
-t3 : . - '( 1'1\' )
.. - ..- --...

• _ ·p- •cc..,.-,·.n, (i') .i;- (i'tl, • •


,t ·: e_,l I l) (l't'L°) 00 l • , .................)"

'X. -=.L- - A.
(' l-1'F'.) • ( I-Ill)- (..a..a.- .-1 i)

= ') -:: :.L --; z._ - ')(,_ - -= 1 =- ;z


-:lo t> .1to -1 D 1

- - 't t 3 'Z o - ··{\'V)


X + -t o - -·CVJ
3 - :z.. ::. 0 ••• (\/ i)

""""'-.....1.h' pk'!..c.-.h °"') (\'¥)

.... z
t
'h_vM½
Lab Program 7: Program code for Egien values and Eigen vectors
A=[8 -6 2;
-6 7 -4;
2 -4 3];
disp("Matrix");
disp(A)
%Eigenvalues and right eigenvectors of matrix A
[V,D]=eig(A)
OUTPUT:
Matrix
8 -6 2
-6 7 -4
2 -4 3
V=
0.3333 0.6667 -0.6667
0.6667 0.3333 0.6667
0.6667 -0.6667 -0.3333
D=
0.0000 0 0
0 3.0000 0
0 0 15.0000

Gauss Elimination Method:


Lab Program 8a: Guass Elimination Method using back substitution
Lab Program 8b: LU Decomposition
Program Code 8b: for LU Decomposition

OUTPUT
Lab Program 8c: Solution of nonlinear equation in single variable using Gauss-Siedal

Gauss Seidal Method


2nd Approximation

I l
Z2 =
418 - 2(9 2375)- ( - 2-8715)] = 4[- 7 6Q:15] = - 1.9006

rd
3- Approximation

1 l
=
X3
2[15 - ( - 2 8723) - ( - l_9QQ6)) = 2[J9_7731) = 9.8866
1 I
y3 =
5[U - 3(9.8866)- 2(- 1.9006)] =
5[- 14.8584] = - 2.9117

I l
Z3 = [8 - 2(9 8866)- ( - 2-9717)] = [- 8.80] ] = - 220
4 4
4,.., Approxrma ion

1 l
x4 =
2[15 -(-29717)-(-UOD )) = i20_171] = 10086

1 I
y4=
5[11 - ;(l0086)- (-22004)] = 5[-14.S:i 4] = -29 l:i

I l
Z4 =
418 - 2(10.086)- ( - 2_9715)] =
4[- 9 2006 = - 2.3001

Y"' Approxrmation
1
X; =1 [15 - - 29' 15) - ( - 23001)] = 2[20.2 Hi]= 10.L,58

1 1
y5 = -=[ll ,-(10 l'.358) - :1( - 2 3001)] =
5(- 1480 I] = -29614

1 ]
25 = -[8 - 2(W 1358)- ( - 2_9614)1 =
41- 93102] = -2.32 5

6th Approxirna ion

1
x6 =il:i-(-2961· )-(-23275)] =
2[20.2$9] = lO.l 5

1
y6 =
5[11 - 3(10_144:i) - 2(-232J5)] =j [- 14_7784) = - 2-9::Si'

7th Approxima ion

1 1
x =il:i -(- 29'557)- ( - 23333)] = [20.289) = lO.l 5
2
1 I
y =
5c11-3( 0.1 5)-2(- 2. 3 3)J =
51-! .,66sJ = -2.953

]
]0.1445) - ( - 2_9534)] = [ - 9.J356] = - 2.'.h39
4
Lab Program 8c: Code for Gauss-Siedal
OUTPUT:
Solution of the system is :
10.143142
-2.952420
-2.333466
9.000000
Lab-Program 8d: Solution of nonlinear equation in single variable using Newton
Raphson Method
21:.1iteration:

J(<i) =fi0.6531) =co,{0.6531)- 0.6531,0.6531 = -0.4606

j (x1) =j(0.6531) = - ,0•65 ;i. ,in(0.6531)- 0.653le0.6531 = - 3.7839

-0.4606
-'2 =0.6531---3.7839

Absoluteerror
•= h. x,1=105313 - o.65311= 0.1211
3rd iteration:

.rh) =fi0.5313) =co${0.53l3). 0.5313,osm = -0.04!8

j (,2) =/(0.5313) = - ,o.m3• ,in(0.5313)-0.5313,o.Bn_= 3.1118

-,, -0.0418
x, =O.),i, - -3.1118
x, = 0.5179
Lab Program -8d: Code using Newton Raphson Method
while abs(fa)> e
fa = eval(subs(y,x,a));
ga = eval(subs(g,x,a));
if ga == O
disp('Division by zero.');
break;
end

b = a - fa/ga;
fprintf('step=%d\ta=%f\tf(a)=%f\n',step,a,fa);
a= b;

if step>N
disp('Not convergent');
break;
end
step = step + 1;
end

fprintf('Root is %f\n', a);


OUTPUT:

Enter non-linear equations: cos(x)-x*exp(x)


Enter initial guess: 1
Tolerable error: 0.00001
Enter maximum number of steps: 20

g=

- exp(x) - sin(x) - x*exp(x)

step=1 a=1.000000 f(a)=-2.177980


step=2 a=0.653079 f(a)=-0.460642
step=3 a=0.531343 f(a)=-0.041803
step=4 a=0.517910 f(a)=-0.000464
step=5 a=0.517757 f(a)=-0.000000
Root is 0.517757
Lab Program 9&10
Ordinary Differential Equations: Introduction to ODE’s, Euler’s method, second
order RungaKutta method, 10 MATLAB ODE45 algorithm in single variable
and multivariables. Transforms: Discrete Fourier Transforms.

Lab Program 9a: Euler’ Methods


Program Code 9a: for Euler’methods:
Lab Program 9b: RungaKutta Method
Lab -Program 9B- Rungekutta method order 2.
Lab Program 9c: ODE 45
12

11.8

11.6
dt2 dt 11.4

y(O)=10 y'(O)=0 11.2

>, 11

>> y = dsolve('D2y + 3*Dy + 2*y = 24', 10.8


1
y(O)=l01, 1Dy(O)=D') 10.6

10.4
y=
10.2
12+2*exp(-2*t)-4*exp(-t)
10

0 2 3
>> ezplot(y, [D 6])

The approximate and exact solutions agree to 6 decimal places. This is a


contrast with the result we had for the same equation when we used
Euler's method.

Solv,er Accuracy Descript:ion


ode4S Medium This should be the
first solver you try

ode23 Low Less accurate


than ode45

ode113 Low to high For


computabonally
intensive
problems
ode15s Low to Use if ode45
medium fails because the
problem is stiff*
Lab Program 9c: ODE 45 for dx/dt=3exp(-t)
To solve a second order ODE, using this as an example.
2nd order ODE using ODE45
d2x dx
- t 5- - 4a:(t) = sin(lO t)
dt2 di
Since ode45 can on solve a first order ode, the above has to be converted to two first order
ODE's as follows, Introduce 2 new state variables a:11a:2 and carry the followingderivation

The above gives 2 new first order ODE's. These are


,
X1 = X2

x;"" -5x2 + 4x1 + sin(lOt)


Now ode45 can be used to solve the above in the same way as was done with the first example.
The only difference is that now a vector is used instead of a scalar,
Lab Program 10: Transforms: Discrete Fourier Transforms
Fourier Transform
xn=[2 3 4 4]
N=length(xn)
n=0:N-1
k=0:N-1;
WN=exp(-1j*2*pi/N);
nk=n'*k;
WNnk=WN.^nk;
Xk=xn*WNnk

Xk =

Columns 1 through 2
13.0000 + 0.0000i -2.0000 + 1.0000i
Columns 3 through 4
-1.0000 - 0.0000i -2.0000 - 1.0000i

Lab Program 11,12,13

Application of MATLAB to analyse problems in basic engineering mechanics,


mechanical vibrations, control system, statistics and dynamics of different
circuits. MATLAB Simulink: Introduction to MATLAB Simulink, Simulink
libraries, development of basic models in Simscape Power.
Introduction to Simulink
Simulink is a software package for modeling, simulating, and analyzing dynamical
systems.
It supports linear and nonlinear systems, modeled in continuous time, sampled time,
or a hybrid of the two.
For modeling, Simulink provides a graphical user interface (GUI) for building
models as block diagrams, using click-and-drag mouse operations.
With this interface, we can draw the models just as we would with pencil and paper
(or depict them as it is done in most textbooks).
Simulink includes a comprehensive block library of sinks, sources, linear and
nonlinear components, and connectors.
We can also customize and create our own blocks.

2.1 Starting Simulink


imuHnk n, 'dn d t brin u
ti b mn ind nt r:
>> imulink
It rn m Ii k n th imulink i n I at

imulink' librar r v r ind Ii n bel will p u p ntin th bl


l f r moo I nstru tion.
imulink' Ii ra r ind I w will p u p ntin th bl k
If r model n.

...
Ub,uy Block ..,
El

El

Oe!K'ription 80

Fig.2 Simulink' library br wser

el in this
fa pi al

I R'- I' ll.


81 k. t.

Ii . 5. ddjn,
ha\' rm I.
rt the output port represented
ill turn i.nl li.n

d ,,,..,n 1h < the boa nd

$ln4, _...

·• . . Bl k iagram f r •
A sine signal is gen (a source) and • sco c
rat th dis ith the
m ignals in f rm
r n"\3

H .7.
unn.in • a ti 11.
s.im.ul ( th lickin
( ►, altcma • , L T, r choose I.art

ck
bl k int.er-es L

2.2 Handling of blocks and J nes


lh lo describes the res ndin key trok r rn
ind "'' ) (.

2.3Slmullnk block I_
n\ libr ri
II k Ii
I

• 11 Ul Ul.


I
nt .


I


• m .
3. Viewing and analyzing simulation results
pl lt win


tl

n.

. . Bl di
'l in

3.2 Using return variables


B• turnin tim an utpul hLt an
nn t.lt th ut ut r j

tum utp t traj B

dia ram f r
4. Modeling mechanical systems with Simulink

4.2 Modollng using SlmMechanlcs


.>nd th ing .Ji tu.at. rs t Lh.
is ilh.1.._<-t:r I! in t..he- _

S. Examples of modeling and control of mechanical systems


s., Dynarn cs modeling for ,..mll -1:enna dl•t\ stat>lltzed photfonn
pl.>Lf rm .b th<>
l"hc st.,,biliz<x.l •
m.e3:Su..rc the hangc o· plat£ rm n rial
k. 115,,0 It.hat it can r.n...i.ke h is fixed on the pl.aLform aiD'\ al

gOC>d
The ot,,jecli f"
a.n n...- dL-.h "'t.a.
f IIYI S: IC'n"L ....; a....;;.c,. u.l I" gi.n-.ba..l" inner
i<nbal arod plal:t 1. ' sirn.u.lal-c the obtained d l.""la,ntl

.model I th<> ta tcstj.ng u.J t.o an.a.I th d nu.c


structure of Lhc _ Ln .iddit:ion. lhes.c- ap lied t <-he
i.Liz.a.tio.n - - t aJ.• 201 ).

Fig.. 11 _ ·n..:,, ,. m Slru l'-ArC


m...-, ,- I n1IOd Ii.I"& u ng ul lh . Th --uJ s ff'I m.cnt
u...)ti ns ore

f ... ;H (.l)

L rqu .."lb.h.lS drivi:n l r,tqu4::! p li :...I b)r I.he dj. ""'I. te:r ZTI'brrier ..U'l:d
rea.ct::ion l b l.h.c .ill.dpce.n t ia."'u'\iC'r .ernbic!-r _

dH
,Fl n1H + H (2)
JI

i"A :;. l.n.c-.rtiaJ dc.r-i alive of th.c v tor H;


,nH: Dcri .illi c of H calculated in arolatlng frame l refe:re:nce;
;;:- : Absolut N'>tarion.al rat ol me)in {r.:un.e;
m ntun'\;
ueappli<>d I th
ili I pU nu> be
-ord d n.._.,,. in ing 1.h.is

( )

t"'_C.A. - ,A. (4)


AB. -A,B.

(5)

A. • C<>St"'COS0su,0[ I_ I I_]

B, -[1 + in20 I , . + cos.a.


,_ o ] 1_
1· -MIZ.
f is irL._,q,igrdfi it_ ppl-yi.rig Lhe- a amt
£. u -·i..ns L.a.a.t.ietrLS bl..a.i..nc...L

- I J
_, ---- ---,i,--------,...'-.l_(s.t?"".,.>- J
,: ,-_-+-,_- .,,,;b-- _ (6
,_-+-,_+J_ ,_+1_ ..... ,.. _ ....... -----

-'-=-"---'...,-= --- '""-'--


,_ +'

(8)

5.1..2 Mod.ollng tho oqu.at.Jons of motion with. Slmull:nk


-inc ...,.. cl in fig.. 12i..s t.h.e ::raph..ic:.aJ r"C"p la • n C,e q . a.ti ,-. (6). (7) a"d ( )- It's btaincd
b '1....1......<iiin.g t.h-c bn.u.l..i..n..k: Ibo
5-2. PJ.llod-lJnig zas ---rt pl.-.tfc>rm
-...e tewa.r-t: pla.t.Corm L"'I a l.ass.t cl.es &T.l£c:n- pc»:slrlo.n. o..n:d mc:>1.1<>:n. - g:tn...-...Uy p.:ro,pc::ased.
i:n, · 1:96..S a§ a flig.h..L '-.a..la.1.or, a...-..ci :s.ti.ll c::: m.m -.1 11.&S..:._....d C :r I. p- (S· t.:--art..., J..91115,S)_ S
. a l.d ra.n,,g Q', npp1ic..!ll· i,o h.a-v 'l:::,,,e ilt"cd L.z-Qm St a..rt. plad,o,rm_ .A.£ e>£
i.n ust:rics &..-,g Lh.. d ign l.nclu c .>C'I'"- a C!, au11:0IT1odvc. u - l .. an.di rn.o -inc ·t l
it.: c:::h-<>l<>S>P- .A...... ,,.c:n,g <> le:&. pL,U<>rm h.a.s- .. L<> siiT,.u..l.a.t.ec ft.ight,. m<><:i. I a
IL..l--.ar ll"Q'V, , ild bridg..a.id i.-. -- cl rru:i,._i.r,,l .. dc-s.ig- a.,,. a.r11.d l.. lt .,_ m..._ ,.
a..n.d. p,o,s-•t:i.on s.a cll te com.m....ru:cad r1. d.l.shcs art.cl t::el_ p<'!"S (t,..,,f.alt.la..b .t-CeJp)..
.l'"J,c- .a.rt p.lall a._rt. cxc<..-y::,,t:i .ra:nigc <>£ <>l:i.C>.r.. a.-,,d a.cx::-t..a:ra.t.cl d ca.s.:i.l
tlc>.l"lied o,ric:r,,.t. ..r1,, plat..f.:::i.rm p.ric;> .ala.rgc, am,Q <>rig.icd.l ,. <>r .. £,or a
glv-cin .s:t:r,,,.u:-b..a::.-a.l ma..ss.,.. a.rw:.t t.hus d ,._t pic::aosit:l I J_.., _ -W,,C pl.a.tf,cu-.'.ln. m.o,cl_ I
b.. C'ra.Lcl ccn:r,pJe:x.. ,-j_d'II a. large- T'l £ cch.;;:..rtic::ia,J <X> t:s l..h.at rc,q1..1..
s:i.E(u.i.l.....it:i<>r'-. t" Sc: ,.,,,..a.rt ·pla.lE<>rm V"a.r h,a:v bol:.irl..eiarl a.-.ctt..:a..aLcd. 1 -W'it..h v--aryi.ni_g

c.c.rrabi:.-.a.t::ii.e>r&S of lcg-plat:£o.-rm ex>r'U"'ICC't..i<>ras... ,,,_e Eu.ll .bly .ap.aYa.llcl ID"'- -a.isr...


L g £ a rigj.d 'bc:>.d.. t.c:>p <>r- boi..1-e pla.t.c- c cd. le n bi..1.-c
.a.> pl..11.c ,a.1-.d
a.t. lea.....-c..t stt111::i PQ-i.rl. <M"'l Lh.c- g-r'Q'L.Ln.d aq, • -
' a.:r, . ......,tf"orm h4.. is n.n t..h,c s-c- plat:c ot sl l.n un.J
JC>i-,. &ho_,.,, lf".ag- :J.S _ h. lc-g. h..a.& l."w<> prr,a.rb!;., ar-. 11...1ppcr a.r11d a .l<>wcr_ ,oo.-...,.c,c1. by a
U.,,dric:a.l j<>i..r,,*- h. t...appcr 1 a..._.. •cd: • 1:.l'11oC" 1.,op pl..at.c r l.irll...i....,.. i<>. I:_
:r,,.._._s. ■.h.c lat..Corm has 6-::? _..1 - 1 mobi.lc pa..rts a:w,d 6-3 - 8 j<>ll"'ILt& t:1"11.e parts_

5.2.1 Modeling the physic.al Plant with SlmMec.hanlc.s


.........
o vi.sa...J1.a..lisc t.h.e- c:o,.-r,b: Jl."'ld: c,,f" t.hi.s SL.l_bsy·.sL .::ct e>l!"'l.C: ,a.£ d, lc....---g sL.J.b $ "- :a.ru.:11 right--<:l.ic:k:
select.. C....00.k: Un.ct.er 1\.4.ask....

..

e blue su.bsysbecn. oon.:ta.i:ns the Stewart plal:form pla.rtl:P" in. £i:g_ _ 'The si.rru. .. ala.ti..on
O"I..Od.e.l in £ig.. 1.:8 is t::h..e c.o:n:trol oI the Ste:"7a..rt"pla.t:form's .a:n,otio:n "'i. l:he: f.n.-lcarprop-0.rt::ional-
i.nt:.egra..l-dc.riva.l:ivc (Pl.D) F.eed.back. sy:5-1_C:Ln. pr t:c-d in.fig_ 19_

ig.. 2.0_ Si.n:""1. u1a..lio:n .l"'CSU.llS


Link for study material simscap material
https://www.bing.com/videos/riverview/relatedvideo?q=what+is+simscape&mid=921D5
2B0D 4485D452FEC921D52B0D4485D452FEC&FORM=VIRE
X

Cl)
CMM#-!M\itM
a

0
"''""
15 £-#;t##h► l;GH•i-ifiPM,1---
" .
- ··.
·
"

0
..
..

\\tllflll• S.,,,oca,,_,

Ywt-, •••11.- •-•n" 0 <,

Wlwtll Slfflsc.p,11Mull!
.. ,_ AIIJ'VA ,,. OJ•ll)JSTI

0 "

, •............. ft,

D,.......1 ....,....,., ,-. , "

=: e • I •ii 'J'gl ti " J\11 W-. J • !':.':.

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