You are on page 1of 16

MINISTRY OF EDUCATION AND SCIENCE OF UKRAINE

National Aviation University

Laboratory Work #1

Researching interface of the MATLAB, working with


numbers and arrays, plotting 1d functions

Klimenko Olexandr

IAN-102
Mentor: prof. Gayev Ye. O.
Kiev
2020
Aims: This Laboratory Work, as well as another ones, is an approximate
plan only how to learn the theme entitled. Students are encouraged to
investigate the theme and to experiment with MATLAB as wide as they
can. And sometimes you make an unexpected discovery indeed  … Your
main task with it is to gather first MATLAB skills and master its plotting
tools.

1) The Matlab interface looks very comfortable. In case of inconvenience,


the interface can be easily changed in the “Preferences” tab. The
Command Window displays commands and the results of their execution,
the texts of executable programs, as well as information about errors;
The Workspace tab allows you to access the Current Directory is used to
set the current directory and the workspace.
The Comand History window, where you can recall previously entered
commands and view it.

2) In order to call MATLAB Help you need to register a command: “help”,


“help factorial”.

>> help factorial


factorial - Factorial of input

This MATLAB function returns the product of all positive integers less
than or
equal to n, where n is a nonnegative integer value.

f = factorial(n)

Reference page for factorial


See also prod

Other uses of factorial


symbolic/factorial
>> help ezplot
ezplot - Easy-to-use function plotter

This MATLAB function plots the expression fun(x) over the default
domain -2π < x
< 2π, where fun(x) is an explicit function of only x.

ezplot(fun)
ezplot(fun,[xmin,xmax])
ezplot(fun2)
ezplot(fun2,[xymin,xymax])
ezplot(fun2,[xmin,xmax,ymin,ymax])
ezplot(funx,funy)
ezplot(funx,funy,[tmin,tmax])
ezplot(...,figure_handle)
ezplot(axes_handle,...)
h = ezplot(...)

Reference page for ezplot

See also ezplot3, ezpolar, function_handle, plot

Other uses of ezplot


fixedpoint/ezplot, symbolic/ezplot
>> help fplot
fplot - Plot function between specified limits

This MATLAB function plots fun between the limits specified by limits.

fplot(fun,limits)
fplot(fun,limits,LineSpec)
fplot(fun,limits,tol)
fplot(fun,limits,tol,LineSpec)
fplot(fun,limits,n)
fplot(fun,lims,...)
fplot(axes_handle,...)
[X,Y] = fplot(fun,limits,...)

Reference page for fplot

See also eval, ezplot, feval, LineSpec, plot

Other uses of fplot


fixedpoint/fplot
3) >> help arith
Arithmetic operators.
+ Plus.
X + Y adds matrices X and Y. X and Y must have the same
dimensions unless one is a scalar (a 1-by-1 matrix).
A scalar can be added to anything.

- Minus.
X - Y subtracts matrix X from Y. X and Y must have the same
dimensions unless one is a scalar. A scalar can be subtracted
from anything.

* Matrix multiplication.
X*Y is the matrix product of X and Y. Any scalar (a 1-by-1 matrix)
may multiply anything. Otherwise, the number of columns of X must
equal the number of rows of Y.

.* Array multiplication
X.*Y denotes element-by-element multiplication. X and Y
must have the same dimensions unless one is a scalar.
A scalar can be multiplied into anything.

^ Matrix power.
Z = X^y is X to the y power if y is a scalar and X is square. If y is an
integer greater than one, the power is computed by repeated
multiplication. For other values of y the calculation
involves eigenvalues and eigenvectors.
Z = x^Y is x to the Y power, if Y is a square matrix and x is a scalar,
computed using eigenvalues and eigenvectors.
Z = X^Y, where both X and Y are matrices, is an error.

.^ Array power.
Z = X.^Y denotes element-by-element powers. X and Y
must have the same dimensions unless one is a scalar.
A scalar can operate into anything.
>> help elfun
Elementary math functions.

Trigonometric.
sin - Sine.
sind - Sine of argument in degrees.
sinh - Hyperbolic sine.
asin - Inverse sine.
asind - Inverse sine, result in degrees.
asinh - Inverse hyperbolic sine.
cos - Cosine.
cosd - Cosine of argument in degrees.
cosh - Hyperbolic cosine.
acos - Inverse cosine.
acosd - Inverse cosine, result in degrees.
acosh - Inverse hyperbolic cosine.
tan - Tangent.
tand - Tangent of argument in degrees.
tanh - Hyperbolic tangent.
atan - Inverse tangent.
atand - Inverse tangent, result in degrees.
atan2 - Four quadrant inverse tangent.
atan2d - Four quadrant inverse tangent, result in degrees.
atanh - Inverse hyperbolic tangent.
sec - Secant.
secd - Secant of argument in degrees.
sech - Hyperbolic secant.
asec - Inverse secant.
asecd - Inverse secant, result in degrees.
asech - Inverse hyperbolic secant.
csc - Cosecant.
cscd - Cosecant of argument in degrees.
csch - Hyperbolic cosecant.
acsc - Inverse cosecant.
acscd - Inverse cosecant, result in degrees.
acsch - Inverse hyperbolic cosecant.
cot - Cotangent.
cotd - Cotangent of argument in degrees.
coth - Hyperbolic cotangent.
acot - Inverse cotangent.
acotd - Inverse cotangent, result in degrees.
acoth - Inverse hyperbolic cotangent.
hypot - Square root of sum of squares.

Exponential.
exp - Exponential.
expm1 - Compute exp(x)-1 accurately.
log - Natural logarithm.
log1p - Compute log(1+x) accurately.
log10 - Common (base 10) logarithm.
log2 - Base 2 logarithm and dissect floating point number.
pow2 - Base 2 power and scale floating point number.
realpow - Power that will error out on complex result.
reallog - Natural logarithm of real number.
realsqrt - Square root of number greater than or equal to zero.
sqrt - Square root.
nthroot - Real n-th root of real numbers.
nextpow2 - Next higher power of 2.

Complex.
abs - Absolute value.
angle - Phase angle.
complex - Construct complex data from real and imaginary parts.
conj - Complex conjugate.
imag - Complex imaginary part.
real - Complex real part.
unwrap - Unwrap phase angle.
isreal - True for real array.
cplxpair - Sort numbers into complex conjugate pairs.

Rounding and remainder.


fix - Round towards zero.
floor - Round towards minus infinity.
ceil - Round towards plus infinity.
round - Round towards nearest integer.
mod - Modulus (signed remainder after division).
rem - Remainder after division.
sign - Signum.

√ x+√ y + √ x−√ y
Calculate √ x− √ y √ x+√ y with x=2 і (a complex number!) and y=3 in
MATLAB:

>> (sqrt((2)+sqrt(3)))/(sqrt((2)-sqrt(3)))+(sqrt((2)-sqrt(3)))/(sqrt((2)+sqrt(3)))

ans =

4.0000

>> sin(47)

ans =

0.1236

>> cos(80)

ans =

-0.1104

>> sin(i)

ans =

0.0000 + 1.1752i

>> cos(i)

ans =

1.5431

>> tan(i)
ans =

0.0000 + 0.7616i

>> exp(i)

ans =

0.5403 + 0.8415i

>> log(-1)

ans =

0.0000 + 3.1416i

4)
>> syms x
>> syms e
>> syms ln
>> F1=1/2*(e^(x)-e^(-x))

F1 =

e^x/2 - 1/(2*e^x)
>> F2=ln*(x+sqrt(x^2+1))

F2 =

ln*(x + (x^2 + 1)^(1/2))

>> ezplot sinh


>> ezplot asinh
>> ezplot F1
>> ezplot F2
>> legend('sinh','asinh','F1','F2')
5)
>> x=7;
>> y=4;
>> x+y

ans =

11

>> pi

ans =

3.141592653589793

>> ezplot('sin(x)',[pi/2 pi])


6)
>> A=[1 2 3;2.1 3.3 4.25;5.7 0.03 -1.7]

A=

1.0000 2.0000 3.0000


2.1000 3.3000 4.2500
5.7000 0.0300 -1.7000

>> r=[2.1 3.3 4.25]

r=
2.1000 3.3000 4.2500

>> c=[2;3.3;3e-2]

c=

2.0000
3.3000
0.0300

7)
>> A=magic(5)

A=

17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9

>> A(:,3)

ans =

1
7
13
19
25

>> A.'

ans =

17 23 4 10 11
24 5 6 12 18
1 7 13 19 25
8 14 20 21 2
15 16 22 3 9
8) The array must have a name. The ":" operator (colon) makes it easy to
perform operations to increase the dimension of arrays. All data MatLab
presents as arrays.

9)
>> format short
>> pi

ans =

3.1416

>> format long


>> pi

ans =

3.141592653589793

10)
>> syms x;
>> a=2;
>> b=3;
>> k1=1;
>> k2=4;
>>ezplot(a*sin(k1*x)+(b*cos(k2*x)), [-2*pi,2*pi]),hold on
11)
ezplot ('t * cos (t)', 't * sin (t)', [0,8 * pi])
>> hold on
>> ezplot ('sin (3 * t) * cos (t)', 'sin (3 * t) * sin (t)', [0, pi])
>> A=ezplot ('t * cos (t)', 't * sin (t)', [0,8 * pi])

A=

Line with properties:

Color: [0.9290 0.6940 0.1250]


LineStyle: '-'
LineWidth: 0.5000
Marker: 'none'
MarkerSize: 6
MarkerFaceColor: 'none'
XData: [1x300 double]
YData: [1x300 double]
ZData: [1x0 double]

Show all properties

>> B=ezplot ('sin (3 * t) * cos (t)', 'sin (3 * t) * sin (t)', [0, pi])

B=

Line with properties:

Color: [0.4940 0.1840 0.5560]


LineStyle: '-'
LineWidth: 0.5000
Marker: 'none'
MarkerSize: 6
MarkerFaceColor: 'none'
XData: [1x300 double]
YData: [1x300 double]
ZData: [1x0 double]

Show all properties

>> legend('A','B')
13) To apply different colors to the curves of the graph, it is enough to
add the first letter of the color in quotation marks to the values in the
"plot" command. Commands grid, xlabel, ylabel, title, axis, legend can
supplement your schedule with additional information and select the
required areas.
14) The whole drawing consists of three objects - the graphic window,
coordinate axes and the graph itself. All three objects are stored in
memory. Each object
has data fields that define its appearance on the screen. To gain access
to the fields of graphic objects it is necessary to have pointers to these
objects. "Property Editor" can be called in the "View" tab.

15)
syms x
y=sin(x);
ezplot(y,[-pi,4*pi])
F=x,ezplot(F,[-pi,4*pi]),figure(1)
ezplot(y,[-pi,4*pi]),hold on
F=x,ezplot(F,[-pi,4*pi]),figure(1)
F=F-x^3/factorial(3),F=x,ezplot(F,[-pi,4*pi,-3 3]),figure(1)
F=F+x^5/factorial(5);
ezplot(F,[-pi,4*pi,-3 3]),figure(1)
F=F-x^7/factorial(7);
F=F-x^7/factorial(7),ezplot(F,[-pi,4*pi,-3 3]),figure(1)
F=F+x^9/factorial(9),ezplot(F,[-pi,4*pi,-3 3]),figure(1)
F=F+x^9/factorial(9),f=x,ezplot(F,[-pi,4*pi,-3 3]),figure(1)

You might also like