0% found this document useful (0 votes)
18 views47 pages

CSE1121 Chapter3

Uploaded by

Taha Misirli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views47 pages

CSE1121 Chapter3

Uploaded by

Taha Misirli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

CSE 1121

Scientific Programming

ENGR 101
Introduction to Programming
Built-in MATLAB Functions
Using Built-in Functions

MATLAB uses function names consistent with


most major programming languages
For example
• sqrt
• sin
• cos
• log %natural logarithm
Function Input can be either scalars or matrices
Function Input can be either scalars or matrices
Using Predefined Functions
• Functions consist of
• Name
• Input (s) %input also called
argument
• Output
In MATLAB
>>sqrt(x) sqrt(4)
ans= ans = 2
result
Some functions require multiple inputs

• Remainder function returns the


remainder in a division problem
• For example the remainder of 10/3, is 1
Some functions return multiple results

• size function determines the number of


rows and columns
You can assign names to the output

The variable names are


arbitrary – choose something
that makes sense in the
context of your problem
Nesting Functions
Elementary Math Functions
Common Computations
• abs(x) absolute value
• sign(x) plus or minus
• exp(x) ex
• log(x) natural log (ln)
• log10(x) logarithm with base 10

Elementary Math Functions
nthroot
Real nth root of real numbers
Y = nthroot(X,N) returns the real nth root of the elements of X
Rounding Functions
Discrete Mathematics
Trigonometric Functions

𝑑𝑒𝑔𝑟𝑒𝑒𝑠=𝑟𝑎𝑑𝑖𝑎𝑛𝑠 ()
180
𝜋

𝑟𝑎𝑑𝑖𝑎𝑛𝑠=𝑑𝑒𝑔𝑟𝑒𝑒𝑠 ()
𝜋
180
DATA Analysis Functions
• Analyzing data statistically in MATLAB is
particularly easy:
• Whole data sets can be represented by a
single matrix
• Built in data analysis functions
Maximum and Minimum
Maximum and Minimum
Maximum and Minimum
Use Transpose to find maximum and
minimum in rows

• MATLAB is column
dominant
Mean and Median

The array x should be sorted in


ascending (increasing) or
descending (decreasing) order.
Sums and Products
Sums and Products
Sorting Values
100-metres Race Results
Hypercar Top Speed
Determining Matrix Size
Normal Distribution
(Gaussian Distribution)
Standard Deviation
68–95–99.7 rule
Random Numbers
To generate uniform random numbers
between other bounds…

>> r = (b-a) * rand(10,1) + a;

a and b are the upper and lower bounds


r is the array of 10 random numbers between a and b
To generate Gaussian random
numbers between other
bounds…
𝑥=𝜎 𝑟 +𝑚𝑒𝑎𝑛
100 random numbers with a mean of 70
and standard deviation of 20
Complex Numbers

Cartesian Polar Coordinate


Coordinate System
System
Complex Numbers

All of these expressions


returns same
Complex Numbers
norm(x): returns the 2-norm or
Euclidian norm of vector x.

On an n-dimensional Euclidean space Rn, the


intuitive notion of length of the vector x =
(x1, x2, ..., xn) is captured by the formula
Computational Limits
• MATLAB’s computational range on most computers is:
• 10-308
• 10308
• When you divide by 0, the computer returns Inf
Special Values and
Miscellaneous Functions

You might also like