A Mathematicians Introduction to MATLAB - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

A Mathematicians Introduction to MATLAB

Description:

Professor Elgindi for giving me this opportunity. ... quad(_at_f,0,pi) Final Thoughts. Nobody could or would want to know everything about MATLAB. ... – PowerPoint PPT presentation

Number of Views:65
Avg rating:3.0/5.0
Slides: 21
Provided by: RLAN4
Category:

less

Transcript and Presenter's Notes

Title: A Mathematicians Introduction to MATLAB


1
A Mathematicians Introduction to MATLAB
  • Robert LangerUWEC (retired)July 2007

2
Thanks
  • Professor Elgindi for giving me this opportunity.
  • Students from Math 351, Fall 2005, and Math 352,
    Spring 2007, especially
  • Dave Kincaid and Steve Henke

3
Plan
  • Basics
  • Linear algebra
  • Ordinary differential equations
  • Partial differential equations

I cant teach you how to use Matlab effectively,
but I hope that I can show you enough so that
when you need Matlab you will know how to start.

4
Session 1
  • Basics
  • Graphing yf(x)
  • User defined functions (M-file)
  • Numerical integration

5
MATLAB Environment
Command Window
CommandHistory
6
Some Important Details
  • Everything is a matrix.
  • Comma or space separates row elements.Semicolon
    separates rows.
  • Elements are referred to by indices in
    parentheses (not square brackets as in Maple).
  • Assignment uses (not )
  • Terminal semicolon () suppresses output.
  • Variable names are Case sensitive.
  • Two sets of arithmetic operations vector,
    element-wise.
  • Previous inputs cant be edited directly.

7
Practice Entering Some Expressions
  • gtgt43sqrt(2)
  • gtgtsin(pi/6)
  • gtgti2
  • gtgtj2 (For electrical engineers)
  • gtgtxlog(10)
  • gtgtyexp(x)

8
Recalculation with MATLAB A frustration for
Maple users
Use the up arrow key
  • In Maple you can select a previous input and
    press Enter to recalculate it.
  • With MATLAB, this will just send you back to the
    current input prompt.
  • To edit and/or recalculate a previous line, press
    the up arrow to scroll back through the worksheet
    until you find what you want to recalculate.
  • Then press Enter

9
Entering a matrix and assigning it to a variable
name
Remember that row elements are separated by
comma or space and rows by semicolon or enter
10
Try the following.
XB , BX , piX , B2 , X2,X.2 , YXX ,
Y2, Y.2,B.B , BB , B.B ,sqrt(X) , exp(X)
, cos(X)
11
Two Kinds of Arithmetic Operations
  • Matrix operations and
  • Element-wise operations . and .

12
Saving your work
  • If you open a saved Maple worksheet it must be
    recalculated. If you exit MATLAB and then start
    it again, the history of your previous work will
    appear, but none of your variables will be known
    in the workspace.
  • You can get the variables back either by
    recalculating them or by Saving the workspace.

13
Help on how to save workspace
14
Warning MATLAB Workspace
  • If you are working on a computer that is not
    your own, and if you are using MATLABs default
    Work folder, be sure to save a copy of your saved
    workspace in your own file space.

15
The Graph of y f(x)
  • plot(X,Y) where X is a vector of domain elements
    and Y is the vector of corresponding values.
  • First example y cos2(x) 1
  • Using X 2,-3 previously defined,
    letY(cos(X)).21

16
How to make a domain vector
  • A slick way to make the vector X a, ah,
    a2h, , b-h, bis gtgt Xahb
  • Lets plot y cos2(x)1 on -p,p with
    hp/18(or make one of your own)
  • gtgt X-pipi/18pigtgt Y(cos(X)).21gtgt
    plot(X,Y)

17
Creating an M-file for a function
  • User defined functions are created in M-files.
  • FilegtNewgtM-File
  • function yf(x) y(cos(x)).21end
  • Since the function is named f it must be saved
    with the filename f.m

18
Numerical Integration
  • Lets compute where f is our previously
    defined function.
  • Search Help for integration.
  • gtgt quad(_at_f,0,pi)

19
Final Thoughts
  • Nobody could or would want to know everything
    about MATLAB.
  • Start with a particular project or problem.
  • Use the Help files.
  • Be willing to try something.
  • Be prepared for frustration.

20
Final Thoughts
  • Nobody could or would want to know everything
    about MATLAB.
  • Start with a particular project or problem.
  • Use the Help files.
  • Be willing to try something.
  • Be prepared for frustration, but if you need
    MATLAB it is worth the frustration.
Write a Comment
User Comments (0)
About PowerShow.com