Lab 1 MATLAB
Lab 1 MATLAB
Lab 1 MATLAB
Faculty of Engineering
Department of Electrical
كلية الهندسة
Engineering قسم الهندسة الكهربائية
ENGR 3032
SCIENTIFIC COMPUTING LANGUAGES
Term Fall 2024
EXPERIMENT 1
Getting started with Scientific Computing Languages
LAB REPORT
[CO 1 ; PI_1_3 ; SO 1 ]
Submitted To
Osamah Alkhalifah
Submitted By
Mohammed Rasheed, 431014033
September 7 , 2024
Theory:
1. Introduction to Matlab/Octave
MATLAB (MATrix LABoratory) and Octave are two interactive software tools for numerical
computations and graphics. Both are especially designed for matrix computations: solving
systems of linear equations, performing matrix transformations, factoring matrices, and so
forth. In addition, they have a variety of graphical capabilities, and can be extended through
programs.
MATLAB and Octave are supported on Linux, Macintosh, and Windows environments.
Getting Started
Using MATLAB/Octave for the first time is easy; mastering it can take years. In this
Laboratory session, we will introduce you to the MATLAB/Octave environment and show
you how to perform basic mathematical computations. After this lab, you should be able to
start using MATLAB for solving engineering problems.
No matter how you start it, once MATLAB/Octave opens, you should see the prompt ( >> ),
which tells you that Matlab/Octave is ready for you to enter a command. For example, the
MATLAB looks as in like Figure 1:
You can perform calculations in the command window in a manner similar to the way you
perform calculations on a scientific calculator.
For example, to compute the value of 5 squared, type the command at the command prompt:
>> 5^2
The following output will be displayed:
ans =
25
2. Getting help
Three useful methods can be utilized to obtain help in Matlab and Octave:
Using the help command: The fastest way to find out information about commands is via the
help command. If you just type help and hit return, you will be presented with a menu of help
options. If you type ‘help’ followed by the name of a command/function,
MATLAB/Octave will provide help for that particular command. For example, ‘help hist’
will call up information on the ‘hist’ command, which produces histograms. Note that the
help command only displays a short summary of how to use the command you are interested
in.
Using the doc command: For more detailed help documentation, use the doc command. For
example, ‘doc hist’ will display the full documentation of the ‘hist’ command, including
examples of how to use it and sample output. The help system provides information to assist
you while using MATLAB/Octave.
Using the lookfor command: Another very useful MATLAB/Octave command is the
‘lookfor’ command. This will also search for commands related to a keyword. Find out which
MATLAB commands are available for plotting using the command ‘lookfor plot’ in the
command window.
Using the help menu item: select Help MATLAB Help to open the help pages. You can
then browse the commands via the Contents window; look through the Index of commands
or Search for keywords or phrases within the documentation.
To create a new script file (also called an M-file) choose File New M-File from the
MATLAB menu bar (in Octave select New script icon or File → New script). This will open
a blank script editor window. You can enter commands into this window using the same
syntax as you would at the MATLAB/Octave command line. These commands can be saved,
repeated and edited.
Example 1: A room is 5 meters in height, 6 meters in width and 7 meters in length. What is
the volume of air that it can hold?
Solution:
Write a description of the solution (provide your name, ID number and a short description of
the problem).
define the corresponding variables:
height = 5
width = 4
find the unknown:
Now save your script file by choosing File Save from the menu in the script file editor. Give
your script file a meaningful name, such as Example_1.m. The .m extension is used to denote
MATLAB/Octave script files. The file will be saved in the working directory.
Now go back to the MATLAB/Octave command line. First, clear the workspace using the
clear or clc commands. Now, at the command prompt enter Example_1 at the command
prompt to execute the script or simply select save and run icon that shows up when editing
the script.
or
Remember that ln(x) is the natural logarithm and that the function ex is an exponential
function. Also, notice that the last expression produces a complex number, which
MATLAB/Octave represents using the special variable i for the imaginary part.
Follow the procedure in Example_1 in order to create a script file and save it in a folder with
file name Lab1_Task2_StudentID.m to calculate the following:
◼ Take a snapshot of the (Note: The snapshot should show your ID and folder name):
✓ your script (code)
✓ MATLAB/Octave output as shown in the Command window after executing the
script and paste it below:
1. What are the general steps that you have followed to solve the problem given in task
2, using scientific computing languages?
1: I can use the help command to find out what a function does
2: I can use the doc command to get more detailed information with examples
3: I can use lookfor to search for functions when I don’t know their exact names
4: I can also use the online documentation or built-in help browser in MATLAB