matlab programming & its applications for electrical engineers

Upload: rohan-sharma

Post on 03-Jun-2018

244 views

Category:

Documents


2 download

TRANSCRIPT

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    1/27

    A

    WORKSHOP ON

    MATLAB PROGRAMMINGITS APPLICATIONS FOR ELECTRICAL

    ENGINEERSOrganized by

    Department of Electrical EngineeringMARUDHAR ENGINEERING COLLEGE,

    Raisar, NH-11, Bikaner

    Created by

    - Rohan Sharma-

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    2/27

    WORKSHOP SCHEDULE

    Day 1 Basics of MATLAB & Familiarization

    Mathematical Operations using MATLAB

    Working with Script files & user defined functions

    Applications of MATLAB in Electrical Circuits

    Day2

    Numerical Methods using MATLAB

    MATLAB Applications in Electrical Power System

    Applications of MATLAB in Power Electronics

    Simulink Toolbox for Electrical Engineers

    2

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    3/27

    Basics of MATLABMATLAB is a software package for high

    performance computations & visualizations.

    It has very wide application in the field of

    engineering & technology.

    The word MATLAB stands for MATrices

    LABoratory.

    3

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    4/27

    MATLABWINDOWS[A] Matlab desktop -

    Workspace: All the information and details of everyvariable entered into the command window isdisplayed here.

    Command History stores history of every command.

    Every operation which we want to perform is to beentered in command window.

    [B] Edi tor Window

    This window is used to write any program, which

    includes many command statements. By using thiswindow one can edit any previously written command.

    [C] Figure Window

    All the figures are shown in a separate figure window. 4

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    5/27

    MATLAB FILE TYPES

    .m Files: Every script and function file iswritten in this format, with .mextension.

    .p Files:This format is fixed for coded files,source codes are neither visible nor be edited

    in these files..mex Files: Any program written in someother language like C, JAVA or FORTRANcan be imported into matlab using .mexextension files.

    .mat Files: These are the machine code ofm-files.

    .fig Files: any figure can be shown by

    machine code using .figextension. 5

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    6/27

    SOME USEFUL COMMANDS>>ver >> help >> clf

    >>computer >> exit >> clock

    >>dir >> quit >> date>>clc >> help >> home

    >>pwd

    6

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    7/27

    ARITHMETIC OPERATIONSArithmetic operation Symbol

    Addition +

    Subtraction -

    Multiplication *

    Right Division /

    Left Division \

    Exponentiation ^

    7

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    8/27

    EXPONENTIAL OPERATIONSFunction Description

    exp(x) Exponential (ex)

    log(x) Natural logarithm

    log10(x) Base 10 logarithm

    sqrt(x) Square root

    8

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    9/27

    TRIGONOMETRIC OPERATIONSFunction Description

    sin(x)Computes the sine of x, where x is in

    radians.

    csc(x)Computes the cosec of x, where x is in

    radians.sind(x)

    Computes the sin of x, where x is in

    degrees.

    asin(x)Computes the arcsine or inverse sine of x,

    where x is in radians.

    sinh(x)Computes the hyperbolic sine of x, where x

    is in radians.

    atanh(x)

    Computes the inverse hyperbolic tangent of

    x. 9

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    10/27

    COMPLEX NUMBER FUNCTIONSFunction Description

    conj(x)

    Computes the complex conjugate of the

    complex number x. Thus, if x is equal to

    a+ib, then conj(x) will be equal to a-ib.

    real(x) Computes the real potion of the complexnumber x.

    imag(x)Computes the imaginary potion of the

    complex number x.

    abs(x) Computes the absolute value of magnitudeof the complex number x.

    angle(x)Computes the angle of the complex number

    x.

    10

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    11/27

    COMMANDS FOR MANAGING VARIABLES

    Command Description

    clear Removes all variables from the memory.

    clear a, b Clears only variables a and b from

    memory.

    who Lists the variables currently in

    workspace.

    whos Displays a lists of the variables currentlyin the memory and their size together

    with information about their bytes &

    class.11

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    12/27

    WORKING WITH ARRAYS

    Row Vector :

    X=[7 5 3 1]

    Column Vector :

    Y=[7; 5; 3; 1]

    12

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    13/27

    EXERCISE:

    Solve the given equations inMATLAB.

    Hint: A=[3X3] B=[3X1] Ans=inv(A)*B

    9942

    20483

    10235

    zyx

    zyx

    zyx

    13

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    14/27

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    15/27

    EXERCISE :

    Write a program to draw thefollowing curves in a spitted single

    window by using the subp lo t

    command. Also use legendcommand to distinguish between

    different plots.

    p = 3x + 5 q = ex

    r = 1/x s = sin(x)

    15

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    16/27

    SOLUTION:

    x = 0:.1:2*pi;

    subplot(2,2,1); plot(3*x+5)

    legend('p')

    title('Plot of 3x+5')

    subplot(2,2,2);

    plot(exp(x)); legend('q')

    title('Plot of exponent of x')

    subplot(2,2,3);

    plot(1./x);

    legend('r')

    title('Plot of 1/x')

    subplot(2,2,4);

    plot(sin(x));

    legend('s')

    title('Plot of Sin(x))

    16

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    17/27

    INPUT - OUTPUT STATEMENTS:

    Input function:

    Syntax: variable = input(string)

    Example: x = input(Enter the value of x)

    Display function:

    Syntax: disp(string)

    Example: disp(I am learning MATLAB)

    fpr int f function:Syntax: fprintf(string, variable, escape character,

    data)

    Example: fprintf(The sum of a & b is =%d \n, sum)

    17

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    18/27

    USE MATLAB IN ELECTRICAL CIRCUITS :

    18

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    19/27

    19

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    20/27

    20

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    21/27

    SOLUTION USNG MATLAB :

    Z = [40 -10 -30;

    -10 30 -5;-30 -5 65];

    V = [10 0 0]';

    % solve for the loop currents

    I = inv(Z)*V;

    % current through RB is calculated

    IRB = I(3) - I(2);

    fprintf('the current through R is %f Amps \n',IRB)

    % the power supplied by source is calculated

    PS = I(1)*10;

    fprintf('the power supplied by 10V source is %f watts\n',PS)

    21

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    22/27

    MATLAB answers are :

    the current through R is 0.037037 Amps

    the power supplied by 10V source is 4.753086watts

    22

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    23/27

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    24/27

    Example:>> x=2.3;

    >> y=3.3;

    >> addtwo(x,y)

    ans =

    5.6000

    24

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    25/27

    Defining of a function

    function [r,theta] = cart2plr(x,y)

    % cart2plr Convert Cartesian coordinates to polar

    coordinates

    % [r,theta] = cart2plr(x,y) computes r and theta with% r = sqrt(x^2 + y^2);

    % theta = atan2(y,x);

    r = sqrt(x^2 + y^2);

    theta = atan2(y,x);

    25

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    26/27

    Example:

    >> [r,th]=cart2plr(2,-.7)

    r =

    2.1190

    th =

    -0.3367

    26

  • 8/12/2019 MATLAB Programming & Its Applications for Electrical Engineers

    27/27

    End of day one.!

    27