0% found this document useful (0 votes)
77 views12 pages

Lebadesus-Francis M.-Matlab-As-Calculator

This document appears to be a lab report for an activity using MATLAB as a calculator. The objectives were to get familiarized with the MATLAB environment and do basic calculations and functions. The procedure demonstrated using MATLAB for basic arithmetic, different types of division, order of operations, variables, built-in functions, and formatting outputs. Exercises had the student calculate arithmetic expressions, exponential/logarithmic expressions, and trigonometric functions in MATLAB. Insight notes the importance of understanding instructions to develop an effective strategy for tasks in MATLAB.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views12 pages

Lebadesus-Francis M.-Matlab-As-Calculator

This document appears to be a lab report for an activity using MATLAB as a calculator. The objectives were to get familiarized with the MATLAB environment and do basic calculations and functions. The procedure demonstrated using MATLAB for basic arithmetic, different types of division, order of operations, variables, built-in functions, and formatting outputs. Exercises had the student calculate arithmetic expressions, exponential/logarithmic expressions, and trigonometric functions in MATLAB. Insight notes the importance of understanding instructions to develop an effective strategy for tasks in MATLAB.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Engineering Department College

of Engineering and Architecture

Northwest Samar State University


Calbayog City
Samar
Philippines

ECE384 Feedback and Control system for ECE Lab

Activity1:
MATLAB as Calculator

Date Performed:
03/10/2023

Experimenter:

Francis M. Lebadesus

Instructor:
Engr. Nickmar N. Balvez

Date Submitted:

03/12023
Northwest Samar State University
Calbayog City, Samar
COLLEGE OF ENGINEERING and ARCHITECTURE
ELECTRONICS ENGINEERING PROGRAM

Name: Francis M. Lebadesus Date Performed: 03/17/23

Course-Year & Section: BSECE-3 Rating:

MATLA

BASICS

ACTIVITY 1

MATLAB as CALCULATOR
OBJECTIVES

• To be familiarized with the MATLAB environment.

• To do basic calculations and use some basic functions.


BASIC CONCEPTS / MATLAB FEATURES
EQUIPMENT AND MATERIALS REQUIRED:

Computer with MATLAB Software

PROCEDURE

A. Starting MATLAB

Launch MATLAB by double clicking the MATLAB icon or finding the program in the Start Menu. The
MATLAB Command appears.

B. Using MATLAB as Calculator

(1) MATLAB can be used as a calculator.


For example, enter the following at the Command Line prompt
» 1+3
and hit return (enter key). The following result is displayed
(Screenshot and save showing the results of the demo)
MATLAB performed the calculation and, since no assignment of the result was made (the
assignment operator, =, was not used) MATLAB assigned the result to the default variable ans
before displaying the answer. Although MATLAB does not use it, the magenta color is used here
to distinguish MATLAB responses from user input.

(2) MATLAB has two types of division.


For example, enter the following at the Command Line prompt and hit return. »
8/3
(Screenshot and save showing the results of the demo)
This is “right” division (the denominator is on the right of the divisor symbol). It is also the
normal division that we would use. The statement is read as “eight divided by three.”

Now enter the following at the Command Line prompt


» 8\3
(Screenshot and save showing the results of the demo)
This is “left” division (the denominator is on the left of the divisor symbol). Although this is not
used much for scalar algebra as shown here, it is used for vector and matrix algebra. The
statement is read as “three divided by eight.”
Note: regardless of whether right or left division, the numerator always appears “above” or
“over” the slash and the denominator always appears “below” or “under” the slash.

(3) MATLAB has rules for evaluating arithmetic expressions.


For example, enter the following at the Command Line prompt
» 3+3/8*2^3*3/2-1
(Screenshot and save showing the results of the demo)
MATLAB evaluates expressions by the order of precedence rules. It will work from left to right,
executing the highest order of precedence first. Then working left to right, it will evaluate the
next order of precedence, etc. In the above arithmetic expression, MATLAB will evaluate the
exponentiation first
3+3/8*2^3*3/2-1 → 3+3/8*8*3/2-1
Next, MATLAB will work left to right evaluating the divisions and
multiplications 3+3/8*8*3/2-1 → 3+0.375*8*3/2-1
3+0.375*8*3/2-1 → 3+3*3/2-1
3+3*3/2-1 → 3+9/2-1
3+9/2-1 → 3+4.5-1

Finally, MATLAB works left to right evaluating the additions and subtractions
3+4.5-1 → 7.5-1 → 6.5

You can control the execution of expressions by using parentheses, ( ), to override the order of
precedence rules. MATLAB will always execute inside parentheses (by the order of precedence
rules) before executing outside the parentheses.
For example, enter the following at the Command Line prompt
» 3+3/8*2^(3*3)/2-1
(Screenshot and save showing the results of the demo)
Why?

For example, enter the following at the Command Line prompt


» 3+3/8*2^(3*3/2)-1
(Screenshot and save showing the results of the demo)
Why?

For example, enter the following at the Command Line prompt


» (3+3/8*2)^(3*3/2)-1
(Screenshot and save showing the results of the demo)

(4) MATLAB uses (user-defined) variable names to capture the results of calculations. You can choose
to capture the results of any calculation in a variable name of your choice. For example, enter
the following at the Command Line prompt
» myname = 4-1
(Screenshot and save showing the results of the demo)

MATLAB performed the calculation and, since the assignment operator, =, was used to assign
the value to the variable named on the left, MATLAB assigned the result to myname before
displaying the answer.

(5) Using variable names allows for series of assignments and


computations. For example, enter the following at the Command Line
prompt
» % calculate the area of a circle
» radius = 5;
» area = pi*radius^2
(Screenshot and save showing the results of the demo)

MATLAB ignored the first line because it started with the comment operator, %. Note that
MATLAB highlights comments in green text. MATLAB also suppressed the output from the
assignment in second line because the assignment statement was terminated by the suppress
display operator,;. Finally, MATLAB performed the calculation requested by the
third line and displayed the result.
Note that the third line is an assignment statement. The right hand side of the
assignment operator is “computer language” that is shorthand for the following
commands (following the order of precedence rules)
Go get the value assigned to radius (in this case 5).
Raise that value to the power 2.
Go get the value from the MATLAB-defined function, pi
Multiply the two values
together Assign the result to
area
(6) MATLAB has pre-defined functions for more complex
computations. For example, enter the following at the
Command Line prompt
» % computing the sine of an angle
» angle_deg = 30;
» sin_deg = sin(angle_deg)
(Screenshot and save showing the results of the demo)

This result is obviously a problem since we know from trigonometry that the sine of
30° is 0.5. What happened? Whenever we use MATLAB functions, we need to know
what values are required by the function and what units the values must have
Try this line instead
» sin_rad = sin(pi*angle_deg/180)
(Screenshot and save showing the results of the demo)

Much better. Remember to provide values with units of radians when using trig
functions in MATLAB.
(7) You can control the number of digits that are displayed in an
answer. For example, enter the following at the Command
Line prompt
» format long
» area
(Screenshot and save showing the results of the demo)

The first time area displayed above, it was under the default setting of format short,
and only 4 digits to the right of the decimal place were shown. Changing the format
specification to format long allows 14 digits to the right of the decimal place to be
shown. Now enter the following at the Command Line prompt
» format short e
» area
(Screenshot and save showing the results of the demo)

Repeat with
» format long e
» area
(Screenshot and save showing the results of the demo)

(8) Ending your MATLAB session.


You can terminate your MATLAB session either by (1) clicking on the X in the upper
right hand corner of the MATLAB Command Window, (2) clicking on File and then
Exit MATLAB at the bottom of the menu, or (3) typing
» quit

EXERCISES:
Screenshot and save showing the results of the demo.
Use comments (%) indicating the activity/exercise of the item

1. Arithmetic Operations. Compute the following. Display 5 digits.


2. Exponential and Logarithmic Expressions. Evaluate each of the following. Display
in 5 digit scientific notation.

3. Trigonometric Functions. Evaluate each of the following. Display in 16-digit


scientific notation.
INSIGHT:

My insight of doing this activity in Octave or MATLAB might be difficult and call for a different strategy
than those that use ordinary coding. Make sure you understand the instructions completely before beginning
the task. It's critical to understand the restrictions and the desired outcome. This will assist you in organizing
your strategy and preventing avoidable errors. Both simple arithmetic operations and complex mathematical
operations can be carried out using MATLAB/OCTAVE as a calculator. Being able to work with matrices and
complex numbers makes it a potent tool for calculations in science and engineering. Simply enter the expression
in the command window and hit Enter to use MATLAB as a calculator.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy