MATLAB beginner tutorial
MATLAB beginner tutorial
2.Vector + Scalar
Code : a=5;
b=[1 2 2 1];
c=a+b
Output : c=[6 7 7 6]
2.Vector - Scalar
Code : a=2;
b=[4 4 3 3];
c=a-b
Output : c=[2 2 1 1]
1. Scalar - scalar
Code : a=5;
b=7;
c=a*b
Output : c=35
2.Vector - Scalar
Code : a=2;
b=[4 4 3 3];
c=a*b
Output : c=[8 8 6 6]
4. vector .* vector
Code : a=[4,5,6];
b=[1 2 3];
c=a.*b
Output: c=[8 10 18]
5. vector * matrix: (vector should be of P dim and matrix
should be of PxY dim)
Code: a=[4,5,6];
b=[1 2 3; 1 2 3; 1 2 3];
c=a*b
Output: c=[15 30 45]
e. EXPONENT: power(a,b)
1. Scalar ^ scalar
Code: a=6;
b=2;
c=power(a,b)
Output: c=36
2. vector ^ scalar: (rather vector.^scalar)
Code: a=[2 2 3 3];
b=2;
c=a.^b
Output: c=[4 4 9 9]
3. scalar .^ vector
Code: b=[2 2 3 3];
a=2;
c=a.^b
Output: c=[4 4 8 8]
3. eye(x[,y])
Code: a=eye(2)
Output: a=[1 0
0 1]
4. min(variable), max(variable)
Code: a=[1 3 5 7 9 11 13]
b=min(a);
c=max(a)
Output: b=1
C=13
5. sqrt(x)
Code: a=sqrt(25)
Output: a=5
6. length(x)
Code: a=[2 3 4 5 6 7];
b=length(a)
Output: b=7
7. sin, cos, tan, asin, acos, atan: this will give the
trigonometric value of scalar as well as of vectors
Code: x=pi/3;
y=0.5;
a=sin(x)
b=cos(x)
c=tan(x)
d=asin(y)
e=acos(y)
f=atan(y)
Output: a=0.8660
b=0.5000
c=1.7321
d=0.5236
e=1.0472
f=0.4636