Lecture 2
Download
1 / 21

lecture 2: - PowerPoint PPT Presentation


  • 284 Views
  • Updated On :

Lecture 2:. Problem Solving Algorithm Matlab Environment. Algorithm. Algorithm: a sequence of instructions that allows us to accomplish some goals.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'lecture 2:' - Angelica


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Lecture 2 l.jpg
Lecture 2:

  • Problem Solving

  • Algorithm

  • Matlab Environment


Algorithm l.jpg
Algorithm

  • Algorithm: a sequence of instructions that allows us to accomplish some goals.

  • The word ”algorithm” comes from the name of a Persian author, Abu Ja’far Mohammed ibn Musa al Khowarizmi (c. 825 A.D.), who wrote a textbook on mathematics.

  • Examples:

    - Directions to a party

    - Recipe

    - Computer programs


Algorithm3 l.jpg
Algorithm

  • Characteristics of an algorithm

    1. Finiteness

    - terminates after a finite number of steps

    2. Input & Output

    3. Definiteness

    - rigorously and umambiguously specified

    4. Effectiveness

    - steps are sufficiently simple and basic


Algorithm4 l.jpg
Algorithm

  • Example: Find the greatest common divisor of a and b:

    GCD(a,b):

    1. Input a and b

    2. If b=0 then output GCD(a,b) = a and stop!

    3. Assign t=b , b= a mod b , a = t

    Go to step 2.

    Notes: GCD(a,b)=GCD(b, a mod b)


Algorithm5 l.jpg
Algorithm

  • GCD(10,6)

    1. a=10, b=6

    2. _

    3. t=6, b= 4, a=6

    2. _

    3. t=4, b=2, a=4

    2. _

    3. t=2, b=0, a=2

    2. GCD(10,6)=2.

GCD(a,b):

1. Input a and b

  • If b=0 then output GCD(a,b) = a and stop!

    3. Assign t=b , b= a mod b , a = t

    Go to step 2.


Algorithm6 l.jpg
Algorithm

  • A good algorithm implemented on a slow computer may perform much better than a bad algorithm implemented on a fast computer.


Algorithm7 l.jpg
Algorithm

  • Minimal spanning tree problem

    - Spanning tree: given a connected graph, a spanning tree is sub-graph (a tree) that connects all the vertices together.

    - MST: is a spanning tree with the shortest total length.



Algorithm9 l.jpg
Algorithm

  • Brute Force attack: enumerate all possible spanning trees and select the best one among them.

    • Given n points, there are nn-2possibilities !!!


Algorithm12 l.jpg
Algorithm

  • Prim’s algorithm for MST is: n2

  • Kruskal’s algorithm for MST is : |E| log |E| + n


Matlab l.jpg
MATLAB

  • MATLAB® is a high-level language and interactive environment that enables you to perform computationally intensive tasks faster than with traditional programming languages such as C, C++, and Fortran.

  • Latest version is R2008a, 7.6 (2008)


Matlab14 l.jpg
MATLAB

  • Matlab’s windows:

    • File: list files in the current directory


Matlab15 l.jpg
MATLAB

  • Workspace: show the variables you have declared


Matlab16 l.jpg
MATLAB

  • Command History: show all commands you have typed so far.


Matlab17 l.jpg
MATLAB

  • Command Window: where to enter your command.


Matlab18 l.jpg
MATLAB

  • Help Browser: will appear when you click to Help in Help Menu (F1)


Matlab19 l.jpg
MATLAB

  • Getting Help !

    • Help command

    • Lookfor command

    • Examples: Lookfor sine

    • Google is your friend

  • Variables

    • Is a tag that you assign to a value while that value remains in memory

    • Variables are defined with the assignment operator

    • Variable names must begin with a letter, which may be followed by any combination of letters, digits, and underscores.

    • Variables names are case-sensitive

    • Examples: x1,x2, m_weight, X1,X2, M_Weight are different variables


Matlab20 l.jpg
MATLAB

  • Some examples:

    1) Calculate BMI

    m_weight=input(‘input your weight (kg): ’);

    m_height=input(‘input your height (m):’);

    bmi=weight/height^2

    2) Calculate area of a doughnut


Matlab21 l.jpg
MATLAB

m_radius_large=input(‘input larger radius: ’);

m_radius_small=input(‘input smaller radius: ’);

m_area=(m_radius_large^2 m_radius_small^2)*pi


ad