matlab
Download
Skip this Video
Download Presentation
= MATLAB

Loading in 2 Seconds...

play fullscreen
1 / 39

= MATLAB - PowerPoint PPT Presentation


  • 117 Views
  • Uploaded on

= MATLAB. Mat hematics + Lab oratory. =. +. MATLAB. Civil Engineering. Dan Ophir, Ph.D. Cell.: 052-551359 e-Mail: [email protected] Requirements. Tests: Intermediate, Final. 75% Lectures + 25% Exercises. Note = Tests + Exercises. Exercises in diskettes

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 ' = MATLAB' - gail


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
matlab
= MATLAB

Mathematics + Laboratory

=

+

MATLAB

Civil Engineering

Dan Ophir, Ph.D.

Cell.: 052-551359

e-Mail: [email protected]

requirements
Requirements
  • Tests:
  • Intermediate,
  • Final.

75% Lectures + 25% Exercises

Note = Tests + Exercises

Exercises in diskettes

1. .rtf format (Office);

2. .m, .mdl, .fig (Matlab)

files
Files

User’s:

  • .m --- Script
  • .mat --- Workspace
  • .mdl --- Block program – Model (Simulink)
conventions
Conventions
  • > - pressing on a menu, sub-menu, button
  • blue – link
  • red – a reserved word.
mode of interaction
Mode of Interaction

Interactive

Batch:

Script

Program

Interpreter

Compiler

slide8
Demo

MATLAB>Matrices>graphs and matrices

MATLAB>Numerics>2D-solutions

MATLAB>Numerics>Command line demos>Run Command line demos >function plot

MATLAB>Visualization>3D plots of comples functions>Run 3D plots of> Cube root

demo 2 cont
Demo (2-cont.)

MATLAB>Language/Graphics>3d surface plots> Run 3D surface plots>color map

work environment
Work Environment

Work- Space

Files

Desktop

Windows

windows
Windows
  • System’s:
  • Commands (history)
  • Variables
  • Help Window
  • Launch Pad
  • Workspace (variables)
  • Array Editor
  • User’s:
  • Script .m
  • Module .mdl
  • Figure .fig
getting starting
Getting Starting

MATLAB: Command Window

  • First commands:
  • helpwin – list of all .m files (scripts) included in the path (described in a help window) > tips (>See also, >Back, >Forward)
  • 2. help - a help in the command window.
  • 3. help debug – a help of special topics or command.
  • lookfor conversion
  • which fprintf
interactive calculation
Interactive Calculation

Command window:

x=5;

y=x+2;

disp(y);

files .matfor workspace saving.

MATLAB.mat – default file name

use: save / load –

to treat with workspace file

who – the local variables values

whos – the local variables data structure

m file editor debugger window
M-File Editor/Debugger window

Input:

1. Command window: setpath

2. Command window: open fibonaci.m file

3. Command window: fibonaci

Output:

1. Command window: Fibonacci series

2. Figure No. 1

fibonnacci
Fibonnacci

1 1 2 3 5 8 13 21…

Converges to the golden ratio.

AB : CB = CB : AC

A

B

C

golden ratio
Golden Ratio

Parthenon

simulink window
Simulink window

Modeling Programming

  • First step:
  • menu:file>new>model
  • or: >open>browsing .mdl
  • gives the model specifications.
  • 3) model - icon
  • Second step:
  • menu: file>open
  • Browsing for .mdl
  • Third step: (Integral window)
  • menu: simulation>start
  • Input & Integration windindows

C:\MATLAB_5\my_examples\mdl\MDL\Simple\INTEGRAL.MDL

matlab as a language
MATLAB as a Language

Language :

Syntax,

Semantics

language components
Language Components

script – function: f(a,b)

command: x=y+5

variable: myBook_1

operator: + *

constant: 3.27

special symbol: % , ; “ ( )

operations operators
Operations (operators)

helpwin>matlab\ops>*

variables
Variables
  • Naming rules:
  • letters, digits, _
  • Case sensitive
  • Starting with a letter

Reserved World List (17)

for end if while function return elseif case otherwise switch continue else try catch global persistent break

control flow keywords
Control Flow keywords

% if - Conditionally execute statements.

% else - IF statement condition.

% elseif - IF statement condition.

% end - Terminate scope of FOR, WHILE, SWITCH and IF statements.

% for - Repeat statements a specific number of times.

% while - Repeat statements an indefinite number of times.

% break - Terminate execution of WHILE or FOR loop.

help>manual>control flow

help>else

functions library
Functions Library

Trigonometric : sin, cot

Exponential : log, exp, ^, sqrt

Complex : conj, real

Rounding and remainder: fix, floor, mod

Coordinate Transformation: carth2sph,pol2cart

Number Theoretic: factor, isprime, gcd

Specialized: besselj, legendre

helpwin> matlab\elfun (topics elem. func) > tan

function syntax
Function Syntax

function [list of output arguments ] = name (input-arg.)

commands…

Example:

function [mean] = avg(x,n)

mean = sum(x)/n;

command
Command

Command: collection of the following entities:

variables, constants, calling functions, keywords (reserved words) and operators.

Examples: x=23+10*sin(0.3);

x

program
Program

Program: A collection of commands with some significance.

>> % fibonnaci - sequence

>> b(1)=1; b(2)=1;

>> for I=3:5,

b(I)=b(I-1)+b(I-2);

end

>> b

>> who

example for matrix
Example: FOR, matrix

Output:

2 3 4 5

3 4 5 6

4 5 6 7

5 6 7 8

6 7 8 9

Command:

>> for i=1:5,

for j=1:4,

a(i,j)=i+j;

end

end

>> a

basewords:

loop, matrix, index

operators: >> : , () ;

column

row

simple for if
Simple for, if

Code:

Output:

for I=1:5

I

end

1 2 3 4 5

I=1; J=2; X=5; X=6;

if x==5

I

else

J

end

1

2

slide30
FAQ

Frequently Asked Questions שאלות שכיחות

>> If

for …

Previous command

language manual
Language Manual

MANUAL.M

MANUAL.M

help manual

script program function
Script, Program, Function

Script, Program, Function :

A collection of commands enclosed between two special commands (module) and having a special task.

exercise 1 list
Exercise 1(list)

Choose 8 Reserved words and explain their function in MATLAB and give examples of their usage.

Use the help features of MATLAB and the manual.m file.

Choose 5 operators not given in the lecture and explain their function

exercise 2 pitagoras
Exercise 2 (Pitagoras)

Input: Two perpendicular sides a,b of a right-angled triangle,

Output: The length of the opposite side c.

Do: To write commands to compute c.

c2 = a2 + b2

c

b

a

simple script sum arr
Simple Script – Sum_Arr

1. a=[1 2 3];

2. n=3;

3. % function f=sum(a,n)

4. % Computing the sum of the elements of an array

5. sum1=0;

6. for i=1:n,

7. sum1=sum1+a(i);

8. end

9. f=sum1;

10. s=sprintf(\'sum:%d\',sum1);

11. disp(s);

fibonacci script recursive
Fibonacci Script(recursive)

1. % fibonaci.m (recusive algorithm)

2. %A script to calculate Fibonacci numbers

3. %first described by Leonardo of Pisa

4. f=[1 1]; n=1;

5. while f(n) + f(n+1) <100

6. f(n+2)=f(n)+f(n+1)

7. n=n+1;

8. end

exercise 3 primes
Exercise 3 (primes)
  • Write a script/function myPrime to print all the prime numbers less than n;
  • Take n=100.
  • Compare the results with those received by using the MATLAB original function.
exercise 4 triangle
Exercise 4: Triangle

Draw (in the .m file) a triangle ,whose vertices are at the points: (5,5), (0,10), (10,10)

שרטט (קובץ .m) משולש שקודקודיו בנקודות הבאות: (5,5),(0,10),(10,10)

ad