0% found this document useful (0 votes)
6 views

Week 1 Part 5 Fundamentals

The document provides an introduction to programming in MATLAB, focusing on mathematical functions and operations. It covers topics such as assigning values to variables, operator precedence, and using built-in mathematical functions. Additionally, it mentions the availability of MATLAB Online for users without the software installed on their computers.

Uploaded by

Ngọc Vi Cao
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Week 1 Part 5 Fundamentals

The document provides an introduction to programming in MATLAB, focusing on mathematical functions and operations. It covers topics such as assigning values to variables, operator precedence, and using built-in mathematical functions. Additionally, it mentions the availability of MATLAB Online for users without the software installed on their computers.

Uploaded by

Ngọc Vi Cao
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Fundamentals

Where do I find MATLAB? Here!

Do I have to have MATLAB installed on my computer right


now? No, you can use MATLAB Online!

© 2023 Introduction to Programming in MATLAB (1), Fundamentals 1


Table of Contents

What we've covered this week in Part 4Mathematical Functions


Arithmetic Operations Introduction to operator precedence
Making use of built-in Mathematical Functions
What we've covered this week in Part 5

MATLAB Live Script

© 2023 Introduction to Programming in MATLAB (1), Fundamentals 2


What we've covered this week in Part 4
This week in Part 4 we learnt about:

 Assigning values to variables


 Entering commands
 The command history
 Variables in the base workspace

© 2023 Introduction to Programming in MATLAB (1), Fundamentals 3


Mathematical Functions
Arithmetic Operations
MATLAB can be used as a very powerful calculator and its operations fall into two basic
groups: unary and binary, the former operating on one quantity and the latter on two. We
shall begin by considering basic arithmetic functions, which are binary (see
Arithmetic Operations).

Arithmetic functions include operators for simple operations like addition (+),
multiplication (x), subtraction (-), division (/), and powers (^) (See cheat sheet for
Operator and Special Characters).

Let’s look at an example:

Now let’s write this using arithmetic functions:

Run the code, is the answer 16?

x1 = (3 - 2)*(3 + 1)^2
© 2023 Introduction to Programming in MATLAB (1), Fundamentals 4
Mathematical Functions
Now you try, write the code for the below equation:

%Insert your code below and check that your answer is 1.


x2 =

© 2023 Introduction to Programming in MATLAB (1), Fundamentals 5


Introduction to operator precedence
Recall BODMAS from high school, which supplied you with a method for approaching
calculations. This is a simplified form of Operator Precedence, which is the rule book for
how MATLAB executes the calculations/commands you present it with. This precedence
and the definitions of these operators will be key in the sections that follow. To get us
started, let us refresh our memory on BODMAS:

Let us apply this knowledge by considering the following question.

© 2023 Introduction to Programming in MATLAB (1), Fundamentals 6


Introduction to operator precedence
Determine the area of a circle with radius of 5 units.

A_circle = pi*5^2

The area of a circle with radius of 5 units is , check that the answers match.

© 2023 Introduction to Programming in MATLAB (1), Fundamentals 7


Making use of built-in Mathematical
Functions
There are several instances where you might want to leverage built in functions, like the
logarithmic, exponential, or trigonometric functions. MATLAB has several built in
functions but the ones you are likely to interact with, for now, are these
mathematical functions. Once you know which function you would like to use, you can
type the function name followed by brackets. MATLAB will automatically show you the
expected input for that function. For example, the square root function () is denoted by
sqrt and MATLAB automatically supplies the user with the in-line pop-up sqrt(x) showing
that this function expects a single input:

You can click on the help icon, , if you need more information on the function and how
to use it. You can also right-click on the function and go to Help to open the related
documentation page. Let us try use one of the built-in functions by considering the
following question.

© 2023 Introduction to Programming in MATLAB (1), Fundamentals 8


Making use of built-in Mathematical
Functions
Use the quadratic formula to determine the x-intercepts of the function

The x-intercepts of the function are found at and .

Run the section, are the answers the same as above?

X_1 = (6 + sqrt((-6)^2 - 4*5*1))/(2*5)


X_2 = (6 - sqrt((-6)^2 - 4*5*1))/(2*5)

© 2023 Introduction to Programming in MATLAB (1), Fundamentals 9


What we've covered this week in Part 5
This week in Part 5 we learnt about:
• Arithmetic operations
• Introduction to operator precedence
• Making use of built-in Mathematical Functions

© 2023 Introduction to Programming in MATLAB (1), Fundamentals 10


MATLAB Live Script
Click on the link below for this lecture’s MATLAB live Script

• Week_1_Part_5_Fundamentals.mlx

© 2023 Introduction to Programming in MATLAB (1), Fundamentals 11

You might also like