0 ratings0% found this document useful (0 votes) 39 views17 pagesMatlab
This is a report based on programing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
3/9/23
Department of Mathematics
Jahangirnagar University
Course:
Math 210 (MATLAB)
Supplementary Book:
Mastering MATLAB by D. Hanselman & B. Littlefield
Instructor:
Dr. Md. Tauhedul Azam
BSc 24 Year, 2021
Math 210 (MATLAB)
= In MATLAB or any other programming language, we depend on
software developers' syntax, not ours.
= MATLAB code runs >> means we applied the syntax perfectly (but
doesn’t mean the answer is correct),
For correct answer what to do???
Study the interpretation of the ‘syntax’ (how it works)
= Always verify the results with the correct answer
2
Scanned with CamScanner3/9/25
«A ________}
Relational & Logical
Operations
Relational Operator
Relational Operator
<
* comparing two quantity.
<=
* provides answers: True (=1) or False (=0). 2
* making decisions (depending on /F ans). |
* to control the flow or order of execution | ==| equal to
of MATLAB commands base on the true or ieee ineenaes
~=| Not equal to
false answer.
Scanned with CamScannerele
3/9/23
condition=a>s en orn ae
ceontiontne (aid 8 falselno) tree T=)
ma
Difference between
a=5 and a=
condition€a==5)
test for the value of ali)=5 is true cr false|
Scanned with CamScanner3/9/72
Relational & Logical Operator
Window
Coluans 2 through 7
10203 4 5 6 7
Coluans 8 through 18
Relational & Logical Operator
Try Yourself
a=1:10;
te WiLL test for the condition
a)==b(i)-2
ts true or false?
Scanned with CamScanneril
Logical Operator
&
|
© tocombine or exclude relational expressions
Bk:
AND: — array element by element
: OR : _arrayelement by element
: NOT:
AND : Scalar
:OR : Scalar
3/9/23
Logical Operator
Scanned with CamScanneron
Relational & Logical Operator
Try Yourself
ard: 40; Ie will test for the condition.
b=10:-1:1; a(i)>1 and b(i)<2 (Element by elenent)
both is true or false?
thea>1&b<2
2
Scanned with CamScannerNe"
3/9/23
That’s All for Today.
Thank you for attention.
Control Flow
decision-making statements
vel the flow of ceonurannd execution using
movaniing structures
Scanned with CamScannerControl Flow
‘Decision making & Branching
+ If-Else-End
* Switch-Case-Constructions
Decision making & Looping
+ For Loops
* While Loops
Control Flow
If Statement
if test expression
(commands evaluated if expression is true)
Scanned with CamScannerjel
3/9/23
Control Flow
if Statement
Control Flow
(commands)
end
if (expression! | expression2) || if (expressiont & expression2)
(commands)
Scanned with CamScanneray,
Control Flow
if-else Statement
if test expression
(commands evaluated if true)
else
(commands evaluated if false)
Control Flow
if-elseif Statements —E——E
if expression! |
(commands evaluated if expression! is true)
elseif expression?
(commands evaluated if expression? is true)
else
(commands evaluated if false)
end
Scanned with CamScanneree
Control Flow _|
:
Switch Statements ___|
switch switch expression
case case expression_|
statements:
(awitch_expression § case_expression)
evaluates an expression and chooses
‘ehecute one of several groups of statenes
Gach chelce ie a case,
case case_expression_2
statements
otherwise
statements
end
2
Write down a MATLAB programming code to create result
sheet for a student using
i.
if-else-if statement and
ji. switch statement.
2
Explain how the program works.
Bty
Scanned with CamScanner
3/9/233/5,
Result Sheet Using if-elseif-else :
i eo(D, eC)
ouse2), credit), gp2) Ig)
ourse3). rei), £90) 160)
‘oune(§), eed) 8) eG)
spt Obained Grade point average =
ums)
m4
Scanned with CamScannerzjel®
gp -sun(reitep sures
Result Sheet Using switch
Result Sheet Using switch
Grade
ours, credit), go. a)
ours), redi2), £92). 2)
course) red), 290
cousel) credit),
y
oD
26
isy{P Obtained Grade pont average = ‘numa
Scanned with CamScanner
23
3/9/233),
[Integration _____
Integral
Derivative: Slope, tangent line .
c
GO «jy FE*N SC) pea) 2x x
mm
* derivative
Integral: antiderivative or inverse derivative
afin)
J rcoax _ [Pu =f@)+te
Procedure of finding integral is integration.
Symbolic Math Toolbox
Integration
—
Q provides functions for solving, plotting,
math equations.
and manipulating symbolic
lets you analytically perform differentiation, integration,
simplification,
transforms, and equation solving,
O results displayed in mathematical typeset.
28
Link for details: httpsi//www.mathworks.com/products/symbolic htmiteal
Scanned with CamScanner
143/9/23
Integration
Symbolic Objects ———
O Special data type. |
Syms
O creates a symbolic object that is automatically assigned to a MATLAB® |
variable with the same name. |
Sym oo
O refers to a symbolic object that can be assigned to a MATLAB variable
with the same name or a different name.
Integration
Sym (Uses and syntax)
Example 1 Example 2 Example 3
oy ows > ris
ee ig re 1 The mummerte results te
aatse-36 aon eel ree a
> itm > aT >
ae Es i Orne syntotic muncter ts
i ms oa represented iv exact rational
fo
a nm la
15
Scanned with CamScanner3/9)2
Integration
‘Syms (Uses and syntax)
Example 3
a Syms crente x y eto, ns symbolic variables
3
Integration
Syntax Syntax(definite Integral)
ung Xs symbole verlabie a J cnsymbole vatobie
ot int(f. a,
>} Fax >| F@)dx
mut x) i ett, xa,b) f
od ieee ‘Command Window
Siterattett regain ea ete ea
sos E Heber: zent a EB ihe 2exets
cate eanian 27 seinen w eS
be
ee
2
16
Scanned with CamScanneroo
3/9/23
Integration
Shade/Plot/Find Area Under a Curve
region bounded by the given function, vertical Ti and the scans,
Rounded by: ea
ayes x \aetine sysbolie variaye
a6
iptet_range, f(ptot_range)}
ang, £(area_x_rang))
elation Peas
(int fx ayb))
area=260
34
Integration
Shade/Plot/Find Area Under a Curve
region bounded by the given function, vertical lines and the x-axis.
Curve between: f(x) =x7=2 & f(x)=0
Bounded by vertical line: x=-3, x=3
7
i
Scanned with CamScanner