Predefined MATLAB - PowerPoint PPT Presentation

1 / 26
About This Presentation
Title:

Predefined MATLAB

Description:

Here is a summary of elementary math functions: abs(x) ... ceil(x): rounds x up. sign(x): returns the sign of x. rem(x,y): returns the remainder of x/y ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 27
Provided by: videoserv6
Category:

less

Transcript and Presenter's Notes

Title: Predefined MATLAB


1
PredefinedMATLAB Functions
2
Matlab Functions
  • MATLAB provides a built-in library of functions
    that include
  • Exponential
  • Logarithmic
  • Trigonometric
  • Inverse Trigonometric
  • Hyperbolic
  • Statistical
  • And many more

3
Matlab Functions
  • Here is a summary of elementary math functions
  • abs(x) computes absolute value of x
  • sqrt(x) calculates square root of x
  • round(x) performs statistical rounding of x
  • fix(x) rounds x towards zero
  • floor(x) rounds x down
  • ceil(x) rounds x up
  • sign(x) returns the sign of x
  • rem(x,y) returns the remainder of x/y

4
Matlab Functions
  • Here is a summary of exponential, logarithmic,
    and trigonometric functions
  • exp(x) calculates ex
  • log(x) computes the natural logarithm of x
  • log10(x) computes the logarithm base 10 of x
  • log2(x) computes the logarithm base 2 of x
  • sin(x) returns the sine of x
  • cos(x) returns the cosine of x
  • tan(x) returns the tangent of x

5
Matlab Functions
  • Here is a summary of inverse trigonometric and
    hyperbolic functions
  • asin(x) returns the arc sine of x
  • acos(x) returns the arc cosine of x
  • atan(x) returns the arc tangent of x
  • sinh(x) computes the hyperbolic sine of x
  • cosh(x) computes the hyperbolic cosine of x
  • tanh(x) computes the hyperbolic tangent of x

6
Matlab Functions
  • Here is a summary of statistical functions
  • min(A) Finds the minimum value in array A
  • max(A) Finds the maximum value in array A
  • mean(A) Finds the average of the values in A
  • median(A) Finds the median of the values in A
  • std(A) Calculates the standard deviation in A
  • erf(x) Evaluates the error function at x
  • rand(N) Forms an NxN matrix of uniformly
    distributed random numbers
  • randn(N) Same but normally distributed

7
Matlab Functions
  • Here is a summary of matrix functions
  • sort(A) Sorts the elements of A ascending
  • sum(A) Adds the values in A
  • prod(A) Multiplies the values in A
  • length(A) determines the largest dimension of A
  • size(A) returns the number of rows and columns
    of A

8
Matlab Functions
  • These are some special characters
  • eps Smallest recognized difference
  • i or j Imaginary number
  • Inf Infinity
  • Nan Not a number
  • pi constant ?

9
Matlab Functions
For example, create the following range
variables X 0.0pi/1002pi Y1 cos(X) Y2
sin(X) Y3 2cos(2X) Y4 2sin(4X) Plot(X,Y
1,X,Y2,X,Y3,X,Y4)
10
Matlab Functions
11
Matlab Functions
12
Matlab Functions
Solve the following equations For ?1 45ยบ and
?2 ?/2.345 A 103/cos(?1) B sqrt( 10 20
30 cos(?1) sin(?2)) C tan(?1) cos(?2)
sin(?2/3.14) D (1-cos(?)) (1-sin(?1)) -2pi-1.1
13
Matlab Functions
14
Matlab Functions
  • Solve the following equations
  • Theta 0 to 2pi with a step of pi/100
  • Y1 1.2sin(Theta)
  • Y2 2.4sin(Theta pi/4)
  • Y3 cos(Theta pi/4) sin(2Theta)
  • Plot all three solutions on the same graph
  • Add title, axis labels, and grid.
  • Save the workspace as Lab08_01.mat
  • Save the plot as Lab08_01.fig

15
(No Transcript)
16
(No Transcript)
17
Matlab Functions
  • Solve the following equations
  • x -5 to 5 with a step of 0.1
  • Plot the solution
  • Add title, axis labels, and grid.
  • Save the workspace as Lab08_02.mat
  • Save the figure as Lab08_02.fig

18
(No Transcript)
19
Matlab Functions
20
Matlab Functions
  • Matlab commands can also be saved in sequence
    using the concept of M-files
  • Click on File -gt New -gt M-File

21
Matlab Functions
  • Enter the following commands
  • clear, clc
  • low_speed 5
  • high_speed 10
  • seed 24
  • rand(seed,seed)
  • t 0103600
  • t t / 3600
  • num length(t)

22
Matlab Functions
  • continue
  • speed (high_speed - low_speed)rand(1,num)
    low_speed
  • table t,speed
  • Save windspd.dat table ascii
  • plot(t,speed)
  • xlabel(time hr)
  • ylabel(speed mph)

23
Matlab Functions
  • continue
  • Add comments to your M-file
  • Save the file as Windspd.m
  • Run the file by clicking Debug -gt Run
  • Save the figure as Windspd.fig

24
Matlab Functions
25
Matlab Functions
26
Matlab Functions
Write a Comment
User Comments (0)
About PowerShow.com