Lebadesus-Francis M.-Matlab-As-Calculator
Lebadesus-Francis M.-Matlab-As-Calculator
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
MATLA
BASICS
ACTIVITY 1
MATLAB as CALCULATOR
OBJECTIVES
PROCEDURE
A. Starting MATLAB
Launch MATLAB by double clicking the MATLAB icon or finding the program in the Start Menu. The
MATLAB Command appears.
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?
(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.
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)
EXERCISES:
Screenshot and save showing the results of the demo.
Use comments (%) indicating the activity/exercise of the item
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.