Matlab
Matlab
Matlab
Operators
𝑥2
y = (ln(x+2)+ 4𝑥 + sin π )(𝑒 /6x)
Help :( For more info type help followed by the name of
the function).
Who :(Returns a list of all variables in the current
workspace).
whos :(Returns the same list with more detailed
information about each variable.
Clear :(Delete the workspace).
Clc :(Delete the command window).
Basic commands
3 6
A= .
1 9
4
B=
7
C= 4 7 5 1
D= 3 5 7 9
2D: 3D:
(plot (x,y), (surf(x,y,z),
ezplot(f,[xi xf]) mesh(x,y,z))
2D plot
2D plot
2D EZplot
3D surf
3D mesh
For : Loop Control
If : Conditional control
Controls
FOR Loop
A program to print the numbers from 1 to 10
A program to calculate the sum of squares of numbers from 1 to n.
While Loop
A program to print the numbers from 1 to 10
A program to display powers of 2 till x=15 (f(x)=2x)
IF(Conditional control)
A program to make a discount of 20% if the no. of books are greater than
5,the cost of the book is 25.
How to write functions
tank draining
a) The tank is initially half full with ℎ 0 = 2 𝑚
𝑄𝑖𝑛 = 0.065 𝑚3 /𝑠𝑒𝑐
𝐴𝑤 = 𝜋 𝑚 2
𝐴ℎ = 0.0025 𝜋 𝑚2 .
t= 0:4000s
Determine ℎ(𝑡) and find its steady state
value numerically.
𝒅𝒉 𝑨𝒉 𝑸𝒊𝒏 𝒕
=− 𝟐𝒈𝒉 +
𝒅𝒕 𝑨𝒘 𝑨𝒘
physics
The angle y of an undamped pendulum with a driving force sin(5𝑡)
satisfies the differential equation:
𝒚′′ = − 𝒔𝒊𝒏 𝒚 + 𝒔𝒊𝒏 𝟓𝒕 .
Simulink
s