SlideShare a Scribd company logo
02/02/2025
EET 1102-Techniques of
Electrical Technology
LECTURE 2: MATLAB PART 1
PROF. ABDULLAH HOSSAIN
NEW YORK CITY COLLEGE OF TECHNOLOGY
02/02/2025
Outline (not necessarily sequential)
1. MATLAB interface
2. Arrays, Vectors, Matrices
3. Arithmetic Operations, Order of Operations, Control Commands
4. Plotting
5. System of Equations
6. Commenting
7. Script Files, Saving Variables
02/02/2025
02/02/2025
Entering Commands and Expressions
1. MATLAB retains your previous keystrokes.
2. Use the up-arrow key to scroll back through the commands.
3. Press the key once to see the previous entry, and so on.
4. Use the down-arrow key to scroll forward.
5. Press the Enter key to execute the command.
02/02/2025
Mathematical Operations
02/02/2025
Session Example
02/02/2025
Order of Operations
02/02/2025
Control Commands
02/02/2025
Does the Variable Exist?
02/02/2025
Clear the Variables
02/02/2025
Special variables and constants
02/02/2025
Complex Numbers
1. The number c1 = 1 – 2i is entered as follows: c1 = 1 -­2i.
2. An asterisk is not needed between i or j and a number, although it is
required with a variable, such as c2 = 5 - i*c1.
3. The expressions y = 7/2*i and x = 7/2i give two different results.
4. y = (7/2)i = 3.5i and x = 7/(2i) = –3.5i
02/02/2025
Numeric display formats
>> format long %16 digits accuracy
>> 1/3
ans =
0.333333333333333
02/02/2025
Variable Types
Variable Description
char Character array
complex Complex data. Cast function takes real and imaginary
components
double Double-precision floating point (64 bits long, range for
negative numbers is -1.79769 x 10^308 to -2.22507 x 10-
308, for positive numbers is 2.22507 x 10^-308 to 1.79769 x
10^308
int8, int16, int32, int64 Signed integer
logical Boolean true or false
single Single-precision floating point (32 bits long)
struct Structure
uint8, uint16, uint32, uint64 Unsigned integer
Fixed-point Fixed-point data types
02/02/2025
Arrays
1. If elements in an array are evenly-spaced out, then you don’t have to type all of them.
2. Format to generate an array:
1. List_name= StartingpointofList: Stepsize : EndingpointofList
3. The numbers 0, 0.1, 0.2, …, 10 can be assigned to the variable u by typing u = 0:0.1:10.
4. To compute w = 5 sin u, for u = 0, 0.1, 0.2, …, 10, the session is;
u = 0:0.1:10;
w = 5*sin(u);
3. The single line, w = 5*sin(u), computed the formula w = 5 sin u, a 101 times.
02/02/2025
Array Index (nth
item of an array)
>>u(7)
ans =
0.6000
>>w(7)
ans =
2.8232
Use the length function to determine how many values are in an array.
>>length(w)
ans =
101
02/02/2025
Arithmetic with Random Arrays
1. If elements in an array are NOT evenly-spaced out, then you DO have to type out all of them.
2. X= [0, 4, 3, 6], defines a one-dimensional array with 4 elements.
3. Y = [1, 2, 3, 0] another one-dimensional array
4. X+Y = [1, 6, 6, 6] (adding 2 arrays)
02/02/2025
Solving for Roots
To find the roots of x^3 – 7x^2 + 40x – 34 = 0, the session is
>>a = [1,-7,40,-34];
>>roots(a)
ans =
3.0000 + 5.000i
3.0000 - 5.000i
1.0000
The roots are x = 1 and x = 3 ± 5i.
02/02/2025
Trigonometric Functions
02/02/2025
Plotting Functions
02/02/2025
Some Plot Commands
02/02/2025
Ginput(n)
02/02/2025
Multiple Plots with Overlaid Text
Plot the following functions on the same plot:
Answer:
>>x = 0:0.01:5; %(0, 0.01, 0.02, 0.03,0.04,…5)
>>y=2*sqrt(x);
>>z=4*sin(3*x);
>>plot(x,y,x,z), xlabel(‘x’), gtext(‘y’), gtext(‘z’), legend (‘square root’,’sin')
After the plot appears on the screen, the program waits for you to position the cursor and click
the mouse button, once for each gtext function used.
02/02/2025
Plotting with different line types
Using different line types for each curve
For previous example change plot(x,y,x,z) to plot(x,y,x,z, ‘ - -’), and it will plot the z-curve with a
dashed line.
02/02/2025
Vectors and Matrices
02/02/2025
Vectors and Matrices
02/02/2025
System of Equations
02/02/2025
System of Equations
02/02/2025
System of Equations
6x + 12y + 4z = 70
7x – 2y + 3z = 5
2x + 8y – 9z = 64
>>A = [6,12,4;7,-2,3;2,8,-9];
>>B = [70;5;64];
>>Solution = AB
Solution =
3
5
-2
The solution is x = 3, y = 5, and z = –2.
Use ‘;’ to separate rows in a MATRIX.
02/02/2025
Comments
The comment symbol may be put anywhere in the line. MATLAB ignores everything to the right
of the % symbol. For example,
>>% “This is a comment. This is ignored by MATLAB.”
>>x = 2+3 % Question 1 of Assignment
x =
5
Note that the portion of the line before the % sign is executed to compute x.
02/02/2025
Prompting User for Numerical/Text Input
02/02/2025
Script Files
1. Running a MATLAB program stored in script file is equivalent to typing all the commands at
once and executing them.
2. Script files can be sent to other users so that it can be run on their MATLAB easily.
3. You can make further edits to the code in the script later on.
4. The name of a script file must begin with a letter, may include digits and the underscore
character, and can be up to 63 characters. Do not use space.
5. Do not give a script file the same name as a variable.
6. Do not give a script file the same name as a MATLAB command or function.
02/02/2025
Linspace
1. The linspace command also creates an evenly spaced-out row vector but you
specify the number of values rather than the increment.
2. The syntax is linspace(a,b,n), where a and b are the lower and upper limits
and n is the number of points; inclusive of the bounds.
3. linspace(5,8,31) means I generate 31 points, including 5 and 8, which are
evenly spaced out.
4. The increment can be determined by: (b-a)/(n-1).
02/02/2025
Magnitude, Length, and Absolute Value
of a Vector
X=[2,-4,5];
The length command gives the number of elements in the vector. length(x)
The magnitude of a vector x having elements x1, x2, …, xn is a scalar, given by
sqrt(x1
2
+ x2
2
+ … + xn
2
), and is the same as the vector's geometric length (recall
Pythagorean theorem A^2+B^2=C^2 where C is the magnitude of the vector).
Use the norm(x) command.
The absolute value of a vector x is a vector whose elements are the absolute
values of the elements of x. Use the abs(x) command.

More Related Content

PPTX
1. Ch_1 SL_1_Intro to Matlab.pptx
PDF
Matlab lec1
PPT
MatlabIntro (1).ppt
PPT
matlab_tutorial.ppt
PPT
matlab_tutorial.ppt
PPT
matlab_tutorial.ppt
PPT
matlab tutorial with separate function description and handson learning
PPTX
Mat lab workshop
1. Ch_1 SL_1_Intro to Matlab.pptx
Matlab lec1
MatlabIntro (1).ppt
matlab_tutorial.ppt
matlab_tutorial.ppt
matlab_tutorial.ppt
matlab tutorial with separate function description and handson learning
Mat lab workshop

Similar to EET Lecture for matlab khjbxiubnxjnkjnw (20)

PPT
matlabchapter1.ppt
PPTX
Matlab introduction
PDF
Matlabch01
PPTX
An Introduction to MATLAB for beginners
PDF
ML-CheatSheet (1).pdf
PPTX
3_MATLAB Basics Introduction for Engineers .pptx
PDF
Lecture 01 variables scripts and operations
PPT
Matlab Basic Tutorial
PDF
Matlab pt1
PPT
Palm m3 chapter1b
PPT
Introduction of MatLab
PPTX
Introduction to MATLAB Programming for Engineers
PPTX
presentation.pptx
PDF
MATLAB Basics-Part1
PDF
Matlab for beginners, Introduction, signal processing
PPTX
Introduction to Matlab and application.pptx
PPT
MATLAB-Introd.ppt
PDF
Programming with matlab session 1
DOCX
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
PPT
Matlab1
matlabchapter1.ppt
Matlab introduction
Matlabch01
An Introduction to MATLAB for beginners
ML-CheatSheet (1).pdf
3_MATLAB Basics Introduction for Engineers .pptx
Lecture 01 variables scripts and operations
Matlab Basic Tutorial
Matlab pt1
Palm m3 chapter1b
Introduction of MatLab
Introduction to MATLAB Programming for Engineers
presentation.pptx
MATLAB Basics-Part1
Matlab for beginners, Introduction, signal processing
Introduction to Matlab and application.pptx
MATLAB-Introd.ppt
Programming with matlab session 1
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
Matlab1
Ad

Recently uploaded (20)

PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
DOCX
573137875-Attendance-Management-System-original
PDF
PPT on Performance Review to get promotions
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPT
introduction to datamining and warehousing
PPTX
additive manufacturing of ss316l using mig welding
PDF
737-MAX_SRG.pdf student reference guides
PPTX
Current and future trends in Computer Vision.pptx
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PPTX
Fundamentals of Mechanical Engineering.pptx
PPT
Mechanical Engineering MATERIALS Selection
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
R24 SURVEYING LAB MANUAL for civil enggi
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
573137875-Attendance-Management-System-original
PPT on Performance Review to get promotions
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
introduction to datamining and warehousing
additive manufacturing of ss316l using mig welding
737-MAX_SRG.pdf student reference guides
Current and future trends in Computer Vision.pptx
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Fundamentals of Mechanical Engineering.pptx
Mechanical Engineering MATERIALS Selection
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Automation-in-Manufacturing-Chapter-Introduction.pdf
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Ad

EET Lecture for matlab khjbxiubnxjnkjnw

  • 1. 02/02/2025 EET 1102-Techniques of Electrical Technology LECTURE 2: MATLAB PART 1 PROF. ABDULLAH HOSSAIN NEW YORK CITY COLLEGE OF TECHNOLOGY
  • 2. 02/02/2025 Outline (not necessarily sequential) 1. MATLAB interface 2. Arrays, Vectors, Matrices 3. Arithmetic Operations, Order of Operations, Control Commands 4. Plotting 5. System of Equations 6. Commenting 7. Script Files, Saving Variables
  • 4. 02/02/2025 Entering Commands and Expressions 1. MATLAB retains your previous keystrokes. 2. Use the up-arrow key to scroll back through the commands. 3. Press the key once to see the previous entry, and so on. 4. Use the down-arrow key to scroll forward. 5. Press the Enter key to execute the command.
  • 12. 02/02/2025 Complex Numbers 1. The number c1 = 1 – 2i is entered as follows: c1 = 1 -­2i. 2. An asterisk is not needed between i or j and a number, although it is required with a variable, such as c2 = 5 - i*c1. 3. The expressions y = 7/2*i and x = 7/2i give two different results. 4. y = (7/2)i = 3.5i and x = 7/(2i) = –3.5i
  • 13. 02/02/2025 Numeric display formats >> format long %16 digits accuracy >> 1/3 ans = 0.333333333333333
  • 14. 02/02/2025 Variable Types Variable Description char Character array complex Complex data. Cast function takes real and imaginary components double Double-precision floating point (64 bits long, range for negative numbers is -1.79769 x 10^308 to -2.22507 x 10- 308, for positive numbers is 2.22507 x 10^-308 to 1.79769 x 10^308 int8, int16, int32, int64 Signed integer logical Boolean true or false single Single-precision floating point (32 bits long) struct Structure uint8, uint16, uint32, uint64 Unsigned integer Fixed-point Fixed-point data types
  • 15. 02/02/2025 Arrays 1. If elements in an array are evenly-spaced out, then you don’t have to type all of them. 2. Format to generate an array: 1. List_name= StartingpointofList: Stepsize : EndingpointofList 3. The numbers 0, 0.1, 0.2, …, 10 can be assigned to the variable u by typing u = 0:0.1:10. 4. To compute w = 5 sin u, for u = 0, 0.1, 0.2, …, 10, the session is; u = 0:0.1:10; w = 5*sin(u); 3. The single line, w = 5*sin(u), computed the formula w = 5 sin u, a 101 times.
  • 16. 02/02/2025 Array Index (nth item of an array) >>u(7) ans = 0.6000 >>w(7) ans = 2.8232 Use the length function to determine how many values are in an array. >>length(w) ans = 101
  • 17. 02/02/2025 Arithmetic with Random Arrays 1. If elements in an array are NOT evenly-spaced out, then you DO have to type out all of them. 2. X= [0, 4, 3, 6], defines a one-dimensional array with 4 elements. 3. Y = [1, 2, 3, 0] another one-dimensional array 4. X+Y = [1, 6, 6, 6] (adding 2 arrays)
  • 18. 02/02/2025 Solving for Roots To find the roots of x^3 – 7x^2 + 40x – 34 = 0, the session is >>a = [1,-7,40,-34]; >>roots(a) ans = 3.0000 + 5.000i 3.0000 - 5.000i 1.0000 The roots are x = 1 and x = 3 ± 5i.
  • 23. 02/02/2025 Multiple Plots with Overlaid Text Plot the following functions on the same plot: Answer: >>x = 0:0.01:5; %(0, 0.01, 0.02, 0.03,0.04,…5) >>y=2*sqrt(x); >>z=4*sin(3*x); >>plot(x,y,x,z), xlabel(‘x’), gtext(‘y’), gtext(‘z’), legend (‘square root’,’sin') After the plot appears on the screen, the program waits for you to position the cursor and click the mouse button, once for each gtext function used.
  • 24. 02/02/2025 Plotting with different line types Using different line types for each curve For previous example change plot(x,y,x,z) to plot(x,y,x,z, ‘ - -’), and it will plot the z-curve with a dashed line.
  • 29. 02/02/2025 System of Equations 6x + 12y + 4z = 70 7x – 2y + 3z = 5 2x + 8y – 9z = 64 >>A = [6,12,4;7,-2,3;2,8,-9]; >>B = [70;5;64]; >>Solution = AB Solution = 3 5 -2 The solution is x = 3, y = 5, and z = –2. Use ‘;’ to separate rows in a MATRIX.
  • 30. 02/02/2025 Comments The comment symbol may be put anywhere in the line. MATLAB ignores everything to the right of the % symbol. For example, >>% “This is a comment. This is ignored by MATLAB.” >>x = 2+3 % Question 1 of Assignment x = 5 Note that the portion of the line before the % sign is executed to compute x.
  • 31. 02/02/2025 Prompting User for Numerical/Text Input
  • 32. 02/02/2025 Script Files 1. Running a MATLAB program stored in script file is equivalent to typing all the commands at once and executing them. 2. Script files can be sent to other users so that it can be run on their MATLAB easily. 3. You can make further edits to the code in the script later on. 4. The name of a script file must begin with a letter, may include digits and the underscore character, and can be up to 63 characters. Do not use space. 5. Do not give a script file the same name as a variable. 6. Do not give a script file the same name as a MATLAB command or function.
  • 33. 02/02/2025 Linspace 1. The linspace command also creates an evenly spaced-out row vector but you specify the number of values rather than the increment. 2. The syntax is linspace(a,b,n), where a and b are the lower and upper limits and n is the number of points; inclusive of the bounds. 3. linspace(5,8,31) means I generate 31 points, including 5 and 8, which are evenly spaced out. 4. The increment can be determined by: (b-a)/(n-1).
  • 34. 02/02/2025 Magnitude, Length, and Absolute Value of a Vector X=[2,-4,5]; The length command gives the number of elements in the vector. length(x) The magnitude of a vector x having elements x1, x2, …, xn is a scalar, given by sqrt(x1 2 + x2 2 + … + xn 2 ), and is the same as the vector's geometric length (recall Pythagorean theorem A^2+B^2=C^2 where C is the magnitude of the vector). Use the norm(x) command. The absolute value of a vector x is a vector whose elements are the absolute values of the elements of x. Use the abs(x) command.