محاضرة بعنوان Mechanical Engineering Applications using GNU Octave

محاضرة بعنوان Mechanical Engineering Applications using GNU Octave
اسم المؤلف
Prof. Rajanarasimha sangam
التاريخ
المشاهدات
135
التقييم
(لا توجد تقييمات)
Loading...
التحميل

محاضرة بعنوان
Mechanical Engineering Applications using GNU Octave
Prof. Rajanarasimha sangam
KJSCE Somaiya Vidyavihar
University Mumbai
What is Octave?

  • Octave is a high-level language, intended primarily for
    numerical calculations. This language provides capabilities
    for numerical resolution of linear and nonlinear problems,
    and for performing other numerical tests. It also provides
    extensive graphical capabilities for data visualization and
    manipulation.
  • Octave is normally used through its interactive command
    line interface, but it can also be used to write noninteractive programs. The Octave programming language
    is quite similar to Matlab, so most programs are reusable
    in this language.
  • In this course we are going to see different aspects of this
    programming language that will help us strengthen certain
    concepts about Octave.
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 28/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 38/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 4GNU Octave
  • It is Mathematical language…..
    – Hence MATRIX is basic Variable
  • In this matrix…
    – Individual element can be
    Number (integer,float…etc)
    Text (Character,string etc)
    Whenever we create any variable in Octave
    By Default it creates a MATRIX having rows
    and columns.
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 5Octave Environment
  • It is a powerful software tool for
    – Performing mathematical computations and
    signal processing
    – Analysing and Visualising data
    – Modelling Physical systems and phenomena
    – Testing Engineering Designs
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 6Industry Applications
  • Aircraft / Defence
  • Robotics
  • Automotive
  • Communications
  • Biotech, Pharmaceutical and Medical
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 7Octave Desktop
  • Command Window: Where you type OCTAVE
    Commands following the prompt: >>
  • Workspace window: It shows all the variable
    you have defined in your current session.
  • Command History: Window displays all the
    OCTAVE commands you have used recentlyeven includes some past sessions.
  • Current Folder: Window displays all the files in
    whatever folder you select to be cuurent.
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 8Requirements for Successful Coding in
    Octave
  • One must learn the exact rules for writing Octave
    statements
  • Need to develop a logical plan of attack for
    solving particular problems
  • Garbage in, garbage out.
  • If you give Octave a garbage instruction, you will
    get a garbage result.
  • With experience you will be able to design,
    develop and implement computational and
    graphical tools for complex engineering and
    science problems.
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 9Arithmetic operators and its order
    Precede
    nce
    Operator
    1 Parenthesis (round brackets)
    2 Power, left to right
    3 Multiplication and Division, left to right
    4 Addition and Subtraction, left to right
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 10Arithmetic Operations
  • Assign values to variables to do arithmetic operations

a= 3 >> b= 10 >> c= (a+b)/a etc

  • Octave has all of the usual mathematical functions that
    are on scientific calculator like sin , cos, tan, log etc
    Carry out simple trigonometric operations
  • Octave has numerous general functions such as “date”,
    “calendar”, ” clc”, “clear”, “who”,”whos” etc
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 11Variables and the workspace
  • Variables are fundamental to coding. In a sense,
    the art of programming is
     getting the right variables at the right time
    A variable name must comply with following rules
     It may consist only of the letters a-z, the digits 0-9
    and underscore ( _ ).
     It must start with a letter.
     Octave is case sensitive
     Give name to variable which is easily distinguishable.
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 12Few Math functions used in octave
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 13Arrays: Vectors and Matrices
  • A Vector is a special type of matrix, having
    only one row, or column. Vectors are also
    referred to as lists or arrays.
  • A matrix is a rectangular object (e.g a table)
    consisting of rows and columns.
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 14Entering Matrix in Octave
  • 4 Ways of entering matrices in Octave
    – Enter an explicit list of elements
    – Load matrices from external data files
    – Generate matrices using built-in functions
    – Create matrices with your own functions in M-files
  • Rules of entering matrices
    – Separate the elements of row with blanks or commas
    – Use a semicolon”;” to indicate the end of each row
    – Surround the entire list of elements with square brackets,[]
  • To enter matrix, simply type:
    B =[1 2 3; 3 5 6;5 7 8]
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 15Defining a Array Explicit list of
    Elements
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 16Defining Array: Initializing vectors:
    linspace, rand etc functions
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 17Defining Array: Explicit list of elements
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 18Indexing of matrices
  • Indexing using parentheses
    A =
    1 2 3
    4 5 6
    7 8 9
    B=A(2,3)
    B = 6
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 19Indexing of matrices ….
    A =
    1 2 3
    4 5 6
    7 8 9
    C =A(1,end)
    C = 3
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 20Indexing submatrices using vectors of
    row and column indices
    A =
    1 2 3
    4 -5 6
    5 6 7
    B=A([2 3],[2 1])
    B =
    -5 4
    6 5
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 21Indexing submatrices using vectors of
    row and column indices
    Ordering of indices is important
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 22Defining matrix with inbuilt functions
    eye function
  • eye function: identity matrix
    X=eye(row_nos,col_nos)
    x=eye(5,5)
    x =
    Diagonal Matrix
    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
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 23Defining matrix with inbuilt functions
    zero function
  • zero function: zeros array ( M –by-N matrix of zeros)
    X=zeros(rows_nos,col_nos)
    X=zeros(5,5)
    X =
    0 0 0 0 0
    0 0 0 0 0
    0 0 0 0 0
    0 0 0 0 0
    0 0 0 0 0
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 24Defining matrix with inbuilt functions
    ones function
  • ones function: ones array(M-by-N matrix of ones)
    X=ones(rows_nos,col_nos)
    X=ones(5,5)
    X =
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 25Matrix manipulations
  • >> a=[ 1 2 3;4 5 6;9 3 6]
  • a =
  • 1 2 3
  • 4 5 6
  • 9 3 6
  • >> b=a‘ (transpose)
  • b =
  • 1 4 9
  • 2 5 3
  • 3 6 6
  • >> c=inv(a)
  • c =
  • -0.44444 0.11111 0.11111
  • -1.11111 0.77778 -0.22222
  • 1.22222 -0.55556 0.11111
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 26Plotting
    2-Dimensional plot
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 27Plotting of given data
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 28Line specifiers in the plot command
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 29Line specifies in the plot() command
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 30Plot of given data using specifiers in
    the plot() command
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 31Creating a plot of a function
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 32Plotting with linspace (Linnearly
    spaced Vectors)
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 33Adding Text to Figures
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 34Use of Xlabel, ylabel and Title
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 35Use of axis command
  • Axis([xmin xmax ymin ymax])
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 36Plotting multiple graphs on the same
    axis
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 37Using plotyy commond
  • Examples of vibrations in machines and
    structures
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 38Use of hold on and hold off command
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 39Plotting multiple graphs in the same plot
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 40Analysis of Truss
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 418/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 428/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 43• >> a=30*pi/180; % angle a= 30 degree
  • >> b=60*pi/180; % angle b =60 degree
  • >> c=45*pi/180; % angle c = 45 degree
  • >> p=200; % force P at joint 3 =200 Newton
  • >> A=[1,0,cos(a),1,0,0;0,0,sin(a),0,1,0;-1,-
    cos(b),0,0,0,0;0,sin(b),0,0,0,1;0,cos(b),-cos(a),0,0,0;0,-sin(b),-sin(a),0,0,0]
  • A =
    ••
    1.00000 0.00000 0.86603 1.00000 0.00000 0.00000
  • 0.00000 0.00000 0.50000 0.00000 1.00000 0.00000
  • -1.00000 -0.50000 0.00000 0.00000 0.00000 0.00000
  • 0.00000 0.86603 0.00000 0.00000 0.00000 1.00000
  • 0.00000 0.50000 -0.86603 0.00000 0.00000 0.00000
  • 0.00000 -0.86603 -0.50000 0.00000 0.00000 0.00000
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 44• >> B=[0,0,0,0,-pcos(c),-psin(c)]
  • B =
    ••
    0.00000 0.00000 0.00000 0.00000 -141.42136 -141.42136
  • >> C=B’
  • C =
    ••
    0.00000
  • 0.00000
  • 0.00000
  • 0.00000
  • -141.42136
  • -141.42136
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 45• >> X=inv(A)*C
  • X =
    ••
    -25.882
  • 51.764
  • 193.185
  • -141.421
  • -96.593
  • -44.829
  • Answers;
  • F1
  • F2
  • F3
  • Ax
  • Ay
  • By
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 46Projectile problem
  • Angle of projections
  • a1=30 deg,a2=45 deg,a3=60 deg
    Velocity of projections
    u1=30 m/s, u2 =45 m/s, u3= 60 m/s
    g=acceleration due to gravity = 10 m/s2.
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 47• >> a1=30;
  • >> a2=45;
  • >> a3=60;
  • >> u1=30; % in m/s
  • >> u2=45; % in m/s
  • >> u3=60; % in m/s
  • >> x=0:10:100;
  • >> y1=xtand(a1)-10x.^2/(2u1.^2(cosd(a1).^2));
  • >> y2=xtand(a2)-10x.^2/(2u2.^2(cosd(a2).^2));
  • >> y3=xtand(a3)-10x.^2/(2u3.^2(cosd(a3).^2));
  • >> plot(x,y1,x,y2,x,y3), grid on
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 48MDOF problems
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 49M=10kg, k=100 N/m
    m=[10 0 0;0 20 0;0 0 20]
    m =
    10 0 0
    0 20 0
    0 0 20
    k=[300 -200 0;-200 300 -100;0 -100 100]
    k =
    300 -200 0
    -200 300 -100
    0 -100 100
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 50• >> D=inv(m)*k % Dynamic matrix
  • D =
  • 30 -20 0
  • -10 15 -5
  • 0 -5 5
  • >> [v,d]=eig(D)
  • v =
  • -0.915255 -0.577350 0.383307
  • 0.398515 -0.577350 0.550204
  • -0.059112 0.577350 0.741857
  • d =
  • Diagonal Matrix
  • 38.7083 0 0
  • 0 10.0000 0
  • 0 0 1.2917
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 51Plot of sine function
  • >> theta =0:0.01:2*pi;
  • >> f=sin(theta); % sin function works on an array
  • >> plot(theta,f,’b’) % 2D plot
  • >> xlabel(‘theta’);
  • >> xlabel(‘theta’); % lebel for X axis
  • >> ylabel(‘sin(theta)’); % label for Y axis
  • >> title(‘plot of sine function’)
  • >> grid on % adding grid line
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 528/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 53Another 2 D plot
  • >> x=0:0.1:15;
  • >> w=15; % omega is 10 rad/sec
  • >> y=exp(-0.7x).sin(w*x);
  • >> plot(x,y), grid on
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 548/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 553 D plot
  • >> t=linespace(0,2,100);
  • error: ‘linespace’ undefined near line 1 column
    3
  • >> t=linspace(0,2,100);
  • >> x=t;
  • >> y=t.^2;
  • >> z=t.^3;
  • >> plot3(x,y,z), grid on
    8/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 568/15/2021 Prof. Rajanarasimha Sangam SVU Mumbai 57

كلمة سر فك الضغط : books-world.net
The Unzip Password : books-world.net

تحميل

يجب عليك التسجيل في الموقع لكي تتمكن من التحميل

تسجيل | تسجيل الدخول