Documente Academic
Documente Profesional
Documente Cultură
%
format long
format short
format rat
vpa(x, 100)
;
,
> < >= <= == ~=
if x >= 10, y = 5;
end
if x == 20
y = 5;
elseif x == 30 y = x;
else
y = 0;
end
switch m
case 1
x = 10
case 2
x = 50
otherwise
x = 60
end
&
|
for x = 1 : 2 : 10
%do stuff
end
while m < 10
m = m + 1;
end
break
continue
clear
clear x y z
clc
x = input('message');
x = input('msg', 's');
\n
\\
disp(['x' ' = ' '10']);
disp(['x', ' = ', '10']);
disp(10);
fprintf('10\n11\n12\n');
fprintf('%2.3f\n', 12.6);
%out 12.600
fprintf('%7.2f\n', 12.657);
%out
12.66
*
.*
/
./
\
.\
^
.^
x = [1, 4, 7, 0, 3, 5];
x = [1; 4; 7; 0; 3; 5]';
x(4)
%Outputs 0
x = [0.2; 0.4; 0.9];
x = [0.2, 0.4, 0.9]';
x(2)
%Outputs 0.4
x = 4 : -2 : -4;
x = (4 : -2 : -4)';
x(4) = 3;
x = [2, 3];
x = [0, x, 4, 5];
x = [0; 1; 2; 3; 4; 5];
x = x(2 : 5);
x = 'hello';
x = ['h', 'e', 'l', 'l', 'o'];
y = [1, 2, 3; 4, 5, 6];
y(2, 3)
%Outputs 6
Arithmetic Operators.
Dot is used to calculate for each element not for
the whole array or matrix.
Declaration of a row array (' for transpose)
(Both are equivalent)
Declaration of a column array
(Both are equivalent)
As
As
As
As
x
x
x
x
=
=
=
=
[4,
[4;
[0,
[0,
2,
2;
0,
1,
0,
0;
0,
2,
-2, -4];
-2; -4];
3];
3, 4, 50];
As x = [1; 2; 3; 4];
length(x)
size(x)
Same thing.
NOTE: a string is an array of characters
Declaration of a 2-dimensional array: 1 2
4 5
Get second column of y.
No of elements of x
Returns no of rows & no of columns
sin(x)
cos
tan
csc **
sec
cot
ADD AN h
ADD AN a
ADD AN d
Sine
Cosine
Tangent
Cosecant
Secant
Cotangent
Hyperbolic. Ex: sinh, cosh
Inverse.
EX: acsc, asech
Use Degree instead of Radians. Ex: sind, acosd
log
log10
exp
i, j
Natural logarithm
Base 10 logarithm
Exponential. Ex: exp(1) %Outputs 2.718281828
x = y(:, 2)
real, imag
conj
angle
pi
inf
3
6
1
Real & Imaginary part of a complex number
Conjugate of a complex number
Phase angle. Ex: angle(1 + i) %Outputs 0.7854 (45o)
(For help about multidimensional arrays & matrices, type doc + function name)
max, min
sum
mean
sqrt
abs
sign
rem(x, y)
mod(x, y)
round
fix
ceil
floor
eye(m, n),
eye(n)
zeros(m, n), zeros(n)
ones(m, n), ones(n)
inv(x)
det(x)
p = [1 0 -26 0 25];
%As P = x4 26x2 + 25
roots(p)
conv(p1, p2)
[q r] = deconv(p1, p2)
polyval(p, k)
polyder(p)
polyint(p, k)
polyfit(x, y, degree)
plot(x,
plot(x,
plot(x,
plot(x,
plot(x,
y)
y,
y,
y,
y,
'+')
'--')
'LineWidth', 4)
':r', x, y, '+g')
title('Parabola no1')
xlabel('This is x axis')
zlabel('This is z axis')
text(5, 10, 'hey')
text(5, 0.5, 'hey',
'FontName', 'Arial',
'FontSize', [14], 'Color',
'r')
%This part in file1.m
function z = f(x)
z = cos(x);
%This part in file2.m
fplot('file1', [0, 10])
loglog(x, y)
semilogx(x, y)
clf
cla
axis([xMin xMax yMin yMax])
axis square
axis off
grid on
%Or off
hold on
%Or off
subplot(3, 4, 5)
quiver(x, y, u, v, s)
syms a w s y
q = a*w - s/(y+3);
findsym(q, 1)
%y
findsym(q, 2)
%y,w
ans(2)
%,
symsum(x, n, m)
symsum(sym('y')^x, x, 5, m)
y = 'x^2-1';
ezplot(y, [-5, 5, -2, 10])
ezplot x^2-1, [-10, 10]
syms x
y = x^2-1;
factor(y)
%(x-1)*(x+1)
factor(x^2-3) %x^2-3
pretty(y)
pretty(x^2-1)
taylor(f, 4)
y = (x-1)*(x+1);
collect(y)
%x^2-1
expand(a*(x+y)) %a*x+a*y
simple(y);
simplify(log(x*y))
%log(x*y)
%(Error if negative)
syms x y positive
simplify(log(x*y))
%log(x)+log(y)
subs(a*x^2+1, a, b) %b*x^2+1
subs(x^2+a*x, a, -1) %x^2-x
isstr(f)
eval('7*5+1')
%36