LAB-1 Introduction To MATLAB: Department of Electrical Engineering Electric Machines
LAB-1 Introduction To MATLAB: Department of Electrical Engineering Electric Machines
Electric Machines
Dated:
20 September, 2016
Semester:
Fall, 2016
Session:
BSEE-14
Name
Reg. No.
10 | P a g e
Report
Marks / 10
Viva
Marks / 5
Total / 15
1.1.2 Step 2
Click Desktop >> Desktop Layout >> Default
1.
2.
3.
4.
5.
Current folder
Command window
Workspace
Current folder
Start Button
11 | P a g e
12 | P a g e
i.
ii.
1. Using MATLAB, Claculate sum and product for above matrix X and A?
_______________________________________________________________________
2. X * A = A* X__________________________________________________(True/False)
13 | P a g e
1.
2.
3.
4.
5.
>>
>>
>>
>>
>>
size(x)
x
x(i,j)
% i is row number and j is colom number
x = 0:1:10;
x(m:n,k:l )% specifies rows m to n and column k
to l.
>> x(:,j)
>> x(i,:)
>> y = linspace (a,b)
>> y = linspace (a,b,n)
(a) start point
(b) end point
(n) no of divisions between a and b
___________________________________________________
14 | P a g e
4. To extract
1. Finding roots
Roots_p1 = roots (p1)
2. Finding polynomial from roots
Poly (roots_p1)
3. Finding value of polynomial at any value
Polyval (p1, x)
4. Multiplication of two polynomial
Conv (a, b)
% multiplies two polynomials a and b
5. Division of two polynomials
1.5.2 Integration
Indefinite integral of symbolic expression E with respect to its sym-bolic variable as defined by
find sym.
>> int (E)
% The int function, when applied to a symbolic expression,
provides a symbolic integration.
15 | P a g e
variable v.
We can solve system of linear equation (value of x, y and z) by using following commands
>> A = [1 2 3; 4 5 6; 7 8 0];
>> B = [1; 1; 1]
>> X = inv(A)*b
Or
X = A\B
16 | P a g e
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
1.7.1.2 Method 2:
>>
>>
>>
>>
x=linspace(0,2*pi,60);
y=sin(x);
plot(x,y)
grid on
1.7.1.3 Method 3:
>> x=linspace(0,2*pi,60);
>> plot(x,sin(x))
17 | P a g e
Plot (x, y, x, u, x, v)
Plot (x, y,cms) % c is color code, m is marker type (*), s is line style (-)
x=linspace (0,2*pi,60);
plot(x,sin(x),'r',x,cos(x),'b',x,cos(x+20),'g')
grid on
=
Domain should be (-
) and
( )
19 | P a g e
function f = factorial(n)
(1)
% FACTORIAL(N) returns the factorial of N.
(2)
% Compute a factorial value.
(3)
f = prod (1: n);
(4)
The first line of a function M-file starts with the keyword function. It gives the function name and order
of arguments. In the case of function factorial, there are up to one output argument and one input
argument.
In addition, it is important to note that function name must begin with a letter, and must be no longer
than the maximum of 63 characters to plot a saved function specify name and limits of x [min max]
20 | P a g e
21 | P a g e
for I = 0: 2: 10
fprintf(yasir)
end
1.8.9.1.2 Step 2
You will have an empty editor to enter list of commands
1.8.9.1.3 Step 3
Now, press the green button to execute the program.
23 | P a g e
When you enter temperature in centigrade and press enter; Command window will show you value in
kelvin.
You can use the function in any script file in same way.
25 | P a g e