LAB 1 - Matlab Basic
LAB 1 - Matlab Basic
Laboratory III
LAB #1
LAB #1
• Introduction to MATLAB as a technical computing tool.
• Defining and managing variables.
MATLAB
A computer program that provides the user
to perform many types of calculations. In
particular, tool to implement numerical
methods.
The Environment
Workspace:
shows a list of
variables created
by MATLAB.
• >> a = 4
• >> x = 2+i*4
Character
Strings
Arrays, Vectors and Matrices
is a collection of values that are represented
by a single variable name.
Note: The scalars used are actually matrices with one row and one column.
Challenge
𝟑 𝟏. 𝟓 𝟐
𝒙=
𝟎. 𝟏 𝟕 𝟏
Colon Operator, : Aside from creating
series of numbers, it
is a powerful tool for creating and
manipulating arrays. can be used to select
Starting value Final value
the individual rows
x = [xi ∶ dx ∶ xf ]
or/and columns of a
increment
matrix.
Functions
MATLAB defined fcn
1.linspace
2.logspace
3.rand
4.magic
5.ones
6.zeros
7.eye
8.and many more …
Character Strings
Aside from numbers, alphanumeric information can be represented by
enclosing the strings within single quotation marks
+ Addition + Addition
- Subtraction - Subtraction
* Multiplication .* Multiplication
/ Division ./ Division
^ Power .^ Power
Try it Yourself !!!
>> x2 = 2/b
1 2 3 × 3 4 5
𝑎(1 × 3) 𝑏(1 × 3)
3 𝑐𝑜𝑙𝑢𝑚𝑛𝑠 ≠ 1 𝑅𝑜𝑤𝑠
𝑌 =𝐴∗𝑋
What if you want to square each element of M?
where a and b are parameters. Write the equation for implementation with
MATLAB, where a = 2, b = 5, and x is a vector holding values from 0 to π/2 in
increments of x = π/40. In addition, compute the vector where each element
holds the square of each element of y. Combine x, y, and z into a matrix w,
where each column holds one of the variables, and display w (short format).
End of LAB #1