0% found this document useful (0 votes)
6 views

MATLAB REPORT

The document is an internship report by Vandana Kumari on MATLAB, submitted as part of her Bachelor of Technology in Electrical Engineering. It covers MATLAB's features, basic syntax, operations, functions, and plotting techniques, providing practical examples and explanations. The report serves as a comprehensive guide for understanding and utilizing MATLAB for mathematical computations and programming.

Uploaded by

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

MATLAB REPORT

The document is an internship report by Vandana Kumari on MATLAB, submitted as part of her Bachelor of Technology in Electrical Engineering. It covers MATLAB's features, basic syntax, operations, functions, and plotting techniques, providing practical examples and explanations. The report serves as a comprehensive guide for understanding and utilizing MATLAB for mathematical computations and programming.

Uploaded by

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

INTERNSHIP REPORT ON MATLAB

1
GOVERNMENT ENGINEERING
COLLEGE ,BHOJPUR

A report submitted in partial fulfillment of the


requirements for
BACHELOR OF TECHNOLOGY
In
ELECTRICAL ENGINEERING
By
NAME: VANDANA KUMARI
Semester- 3rd
Reg no.:22103156907
Roll no- 22EE71LE

2
Signature Signature

(Internal Examiner) (External Examiner)

3
ACKNOWLEDGEMENT

It is my pleasure to be indebted to various people who directly or


indirectly helped me to learn this course and who influenced my
thinking behavior and acts during
study.
I am thankful to the instructor of this course for his support and
cooperation provided to me during the INTERNSHIP.
I also extend my sincere appreciation to mentor Internshala Trainings
who provided their valuable suggestion and precious time for helping me
out in completing my course.
I perceive as this opportunity as a big milestone in my carrier
development. I will
strive to use gained skills and knowledge in the best viable way.
I will continue to
work on the improvement to attain desired carrier objective and hope to
continue
cooperation with all of you in future.

VANDANA KUMARI

4
STUDENT’S DECLARATION

I undersigned VANDANA KUMARI a student of B.TECH 3rd


semester,
declare that I have completed my six weeks internship at
INTERNSHALA from 2nd February 2023 to 16 March 2023 in
“ MATLAB ” .

This work is submitted in the partial fulfillment of the


requirement of internship work for the degree of
Bachelor of Technology in Electrical Engineering. The
results embodied in this work have not been submitted to
any other
University or Institute for the award of any degree or
diploma.

Vandana kumari

July ,2023

5
TABLE OF CONTENTS

1. Introduction

2. Basic syntax

3. Variables

4. Operation

5. Function

6. Plotting

6
1.INTRODUCTION

MATLAB is a software package for high-performance mathematical computation, visualization, and


programming environment. It provides an interactive environment with hundreds of built-in functions for
technical computing, graphics, and animations.

MATLAB stands for Matrix Laboratory. MATLAB was written initially to implement a simple approach to
matrix software developed by the LINPACK (Linear system package) and EISPACK (Eigen system
package) projects.

MATLAB is a modern programming language environment, and it has refined data structures, includes
built-in editing and debugging tools, and supports object-oriented programming.

MATLAB is Multi-paradigm. So, it can work with multiple types of programming approaches, such as
Functional, Object-Oriented, and Visual.

MATLAB is used in various disciplines of engineering, science, and economics.

MATLAB allows several types of tasks, such as manipulations with matrix, algorithm implementation, data,
and functions plotting, and can interact with programs written in other programming languages.

MAIN FEATURES AND C APABILITIES OF MATLAB


The diagram in the figure shows the main features and capabilities of MATLAB. MATLAB's built-in
functions provide excellent tools for linear algebra computations, data analysis, signal processing,
optimization, numerical solution of ordinary differential equations (ODEs), quadrate, and many other
types of scientific calculations.

Most of these functions use state-of-the-art algorithms. These are numerous functions for 2-D and 3-D
graphics, as well as for animations.

7
MATLAB supports an external interface to run those programs from within MATLAB. The user is not
limited to the built-in functions; he can write his functions in the MATLAB language.There are also various
optional "toolboxes" available from the developers of MATLAB. These toolboxes are a collection of
functions written for primary applications such as symbolic computations, image processing, statistics,
control system design, and neural neutral network.

8
The MATLAB desktop environment helps a person to run his commands, manage files and also
helps them to view their desired result. We can change the desktop layout and the various
preferences, such as initial working folder, fonts and keyboard shortcuts by our convenience.

STARTING MATLAB | MATLAB WINDOWS


Now let us consider that the MATLAB is already installed on the system and a user can start the
program. Once the program starts, the windows that open, shown below

9
2.BASIC SYNTAX
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.

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 90o
When you click the Execute button, or type Ctrl+E, MATLAB executes it
immediately and the result returned is −
ans = 1
Another example,
7/0 % Divide by zero
When you click the Execute button, or type Ctrl+E, MATLAB executes it
immediately and the result returned is −
ans = Inf

10
warning: division by zero
Another example,
732 * 20.3
When you click the Execute button, or type Ctrl+E, MATLAB executes it
immediately and the result returned is −
ans = 1.4860e+04
MATLAB provides some special expressions for some mathematical symbols,
like pi for π, Inf for ∞, i (and j) for √-1 etc. Nan stands for 'not a number'.

USE OF SEMICOLON (;) IN MATLAB


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

ADDING COMMENTS

The percent symbol (%) is used for indicating a comment line. For example,
x=9 % assign the value 9 to x
You can also write a block of comments using the block comment operators %
{ and % }.
The MATLAB editor includes tools and context menu items to help you add,
remove, or change the format of comments.

3.VARIABLES

11
In MATLAB environment, every variable is an array or matrix.
You can assign variables in a simple way. For example,

x=3 % defining x and initializing it with a value


MATLAB will execute the above statement and return the
following result −
x=3

It creates a 1-by-1 matrix named x and stores the value 3 in


its element. Let us check another example,

x = sqrt(16) % defining x and initializing it with an expression


MATLAB will execute the above statement and return the
following result −
x=4
Please note that −
 Once a variable is entered into the system, you can refer
to it later.
 Variables must have values before they are used.
 When an expression returns a result that is not assigned
to any variable, the system assigns it to a variable
named ans, which can be used later.

12
For example,

sqrt(78)
MATLAB will execute the above statement and return the
following result −
ans = 8.8318
You can use this variable ans −

sqrt(78);
9876/ans
MATLAB will execute the above statement and return the
following result −
ans = 1118.2
Let's look at another example −

x = 7 * 8;
y = x * 7.89

MATLAB will execute the above statement and return the


following result

y = 441.84

13
4.OPERATION
MATLAB allows two different types of arithmetic operations −

 Matrix arithmetic operations


 Array arithmetic operations
Matrix arithmetic operations are same as defined in linear algebra. Array operations are executed
element by element, both on one dimensional and multi-dimensional array.
The matrix operators and arrays operators are differentiated by the period (.) symbol. However, as the
addition and subtraction operation is same for matrices and arrays, the operator is same for both cases.
The following table gives brief description of the operators –

Sr.No. Operator & Description

1
+
Addition or unary plus. A+B adds the values stored in variables A and B. A and
B must have the same size, unless one is a scalar. A scalar can be added to a
matrix of any size.

2
-
Subtraction or unary minus. A-B subtracts the value of B from A. A and B
must have the same size, unless one is a scalar. A scalar can be
subtracted from a matrix of any size.

3
*
Matrix multiplication. C = A*B is the linear algebraic product of the
matrices A and B. More precisely,

For non-scalar A and B, the number of columns of A must be equal to the


number of rows of B. A scalar can multiply a matrix of any size.

4
.*
Array multiplication. A.*B is the element-by-element product of the arrays
A and B. A and B must have the same size, unless one of them is a scalar.

5
/

14
Slash or matrix right division. B/A is roughly the same as B*inv(A). More
precisely, B/A = (A'\B')'.

6
./
Array right division. A./B is the matrix with elements A(i,j)/B(i,j). A and B
must have the same size, unless one of them is a scalar

7
\
Backslash or matrix left division. If A is a square matrix, A\B is roughly
the same as inv(A)*B, except it is computed in a different way. If A is an n-
by-n matrix and B is a column vector with n components, or a matrix with
several such columns, then X = A\B is the solution to the equation AX = B.
A warning message is displayed if A is badly scaled or nearly singular.

8
.\
Array left division. A.\B is the matrix with elements B(i,j)/A(i,j). A and B
must have the same size, unless one of them is a scalar.

9
^
Matrix power. X^p is X to the power p, if p is a scalar. If p is an integer, the
power is computed by repeated squaring. If the integer is negative, X is
inverted first. For other values of p, the calculation involves eigenvalues
and eigenvectors, such that if [V,D] = eig(X), then X^p = V*D.^p/V.

10
.^
Array power. A.^B is the matrix with elements A(i,j) to the B(i,j) power. A
and B must have the same size, unless one of them is a scalar.

11
'
Matrix transpose. A' is the linear algebraic transpose of A. For complex
matrices, this is the complex conjugate transpose.

12
.'
Array transpose. A.' is the array transpose of A. For complex matrices,
this does not involve conjugation.

EXAMPLE
The following examples show the use of arithmetic operators on scalar data. Create a script file with the
following code −
a = 10;
b = 20;

15
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.50000
g= 2
z = 343

RELATIONAL OPERATORS
Relational operators can also work on both scalar and non-scalar data. Relational
operators for arrays perform element-by-element comparisons between two arrays and
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 following table shows the relational operators available in MATLAB −
Show Examples

Sr.No. Operator & Description

1
<
Less than

2
<=
Less than or equal to

3
>
Greater than

4
>=

5
==

16
Equal to

6
~=
Not equal to

17
5 .FUNCTION
A function is a group of statements that together perform a task. In MATLAB, functions
are defined in separate files. The name of the file and of the function should be the
same.
Functions operate on variables within their own workspace, which is also called
the local workspace, separate from the workspace you access at the MATLAB
command prompt which is called the base workspace.
Functions can accept more than one input arguments and may return more than one
output arguments.
Syntax of a function statement is −
function [out1,out2, ..., outN] = myfun(in1,in2,in3, ..., inN)

EXAMPLE
The following function named mymax should be written in a file named mymax.m. It
takes five numbers as argument and returns the maximum of the numbers.
Create a function file, named mymax.m and type the following code in it −
function max = mymax(n1, n2, n3, n4, n5)

%This function calculates the maximum of the


% five numbers given as input
max = n1;
if(n2 > max)
max = n2;
end
if(n3 > max)
max = n3;
end
if(n4 > max)
max = n4;
end
if(n5 > max)
max = n5;
end
The first line of a function starts with the keyword function. It gives the name of the
function and order of arguments. In our example, the mymax function has five input
arguments and one output argument.
The comment lines that come right after the function statement provide the help text.
These lines are printed when you type

18
help mymax
MATLAB will execute the above statement and return the following result −
This function calculates the maximum of the
five numbers given as input
You can call the function as −
mymax(34, 78, 89, 23, 11)
MATLAB will execute the above statement and return the following result −
ans = 89

ANONYMOUS FUNCTIONS
An anonymous function is like an inline function in traditional programming languages,
defined within a single MATLAB statement. It consists of a single MATLAB expression
and any number of input and output arguments.
You can define an anonymous function right at the MATLAB command line or within a
function or script.
This way you can create simple functions without having to create a file for them.
The syntax for creating an anonymous function from an expression is
f = @(arglist)expression
EXAMPLE
In this example, we will write an anonymous function named power, which will take two
numbers as input and return first number raised to the power of the second number.
Create a script file and type the following code in it –
power = @(x, n) x.^n;
result1 = power(7, 3)
result2 = power(49, 0.5)
result3 = power(10, -10)
result4 = power (4.5, 1.5)
When you run the file, it displays −
result1 = 343
result2 = 7
result3 = 1.0000e-10
result4 = 9.5459

19
6.PLOTTING

To plot the graph of a function, you need to take the following steps −
 Define x, by specifying the range of values for the variable x, for which the
function is to be plotted
 Define the function, y = f(x)
 Call the plot command, as plot(x, y)
Following example would demonstrate the concept. Let us plot the simple function y =
x for the range of values for x from 0 to 100, with an increment of 5.
Create a script file and type the following code −
x = [0:5:100];
y = x;
plot(x, y)
When you run the file, MATLAB displays the following plot

Let us take one more example to plot the function y = x2. In this example, we will draw
two graphs with the same function, but in second time, we will reduce the value of
increment. Please note that as we decrease the increment, the graph becomes
smoother.
Create a script file and type the following code −
x = [1 2 3 4 5 6 7 8 9 10];
x = [-100:20:100];

20
y = x.^2;
plot(x, y)
When you run the file, MATLAB displays the following plot –

ADDING TITLE, LABELS, GRID LINES AND SCALING ON


THE GRAPH
MATLAB allows you to add title, labels along the x-axis and y-axis, grid lines and also to
adjust the axes to spruce up the graph.
 The xlabel and ylabel commands generate labels along x-axis and y-axis.
 The title command allows you to put a title on the graph.
 The grid on command allows you to put the grid lines on the graph.
 The axis equal command allows generating the plot with the same scale factors
and the spaces on both axes
 the spaces on both axes.
 The axis square command generates a square plot.

EXAMPLE
Create a script file and type the following code −
x = [0:0.01:10];
y = sin(x);
plot(x, y), xlabel('x'), ylabel('Sin(x)'), title('Sin(x) Graph'),

21
grid on, axis equal

MATLAB generates the following graph-

DRAWING MULTIPLE FUNCTIONS ON THE SAME GRAPH


You can draw multiple graphs on the same plot. The following example demonstrates
the concept −
EXAMPLE
Create a script file and type the following code −
x = [0 : 0.01: 10];
y = sin(x);
g = cos(x);
plot(x, y, x, g, '.-'), legend('Sin(x)', 'Cos(x)')
MATLAB generates the following graph −

22
SETTING COLORS ON GRAPH
MATLAB provides eight basic color options for drawing graphs. The following table
shows the colors and their codes −

Code Color

w White

k Black

b Blue

r Red

c Cyan

g Green

m Magenta

23
y Yellow

EXAMPLE-
Let us draw the graph of two polynomials
 f(x) = 3x4 + 2x3+ 7x2 + 2x + 9 and
 g(x) = 5x3 + 9x + 2
Create a script file and type the following code −
x = [-10 : 0.01: 10];
y = 3*x.^4 + 2 * x.^3 + 7 * x.^2 + 2 * x + 9;
g = 5 * x.^3 + 9 * x + 2;
plot(x, y, 'r', x, g, 'g')
When you run the file, MATLAB generates the following graph –

SETTING AXIS SCALES


The axis command allows you to set the axis scales. You can provide minimum and
maximum values for x and y axes using the axis command in the following way −
axis ( [xmin xmax ymin ymax] )
The following example shows this −
EXAMPLE

24
Create a script file and type the following code −
x = [0 : 0.01: 10];
y = exp(-x).* sin(2*x + 3);
plot(x, y), axis([0 10 -1 1])
When you run the file, MATLAB generates the following graph –

GENERATING SUB-PLOTS
When you create an array of plots in the same figure, each of these plots is called a
subplot. The subplot command is used for creating subplots.
Syntax for the command is −
subplot(m, n, p)
where, m and n are the number of rows and columns of the plot array and p specifies
where to put a particular plot.
Each plot created with the subplot command can have its own characteristics. Following
example demonstrates the concept −
EXAMPLE
Let us generate two plots −
y = e−1.5xsin(10x)
y = e−2xsin(10x)

25
Create a script file and type the following code −
x = [0:0.01:5];
y = exp(-1.5*x).*sin(10*x);
subplot(1,2,1)
plot(x,y), xlabel('x'),ylabel('exp(–1.5x)*sin(10x)'),axis([0 5 -1 1])
y = exp(-2*x).*sin(10*x);
subplot(1,2,2)
plot(x,y),xlabel('x'),ylabel('exp(–2x)*sin(10x)'),axis([0 5 -1 1])
When you run the file, MATLAB generates the following graph –

26

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