0% found this document useful (0 votes)
2 views3 pages

Basic Operations

The document provides an overview of basic operations in programming, including arithmetic, logarithmic, and trigonometric functions, as well as vector initialization and manipulation. It also covers element-wise operations and matrix multiplication, demonstrating how to work with vectors and perform calculations. Additionally, it introduces the concept of exponential signals with imaginary powers and includes examples of plotting these signals.

Uploaded by

Muhammad Tarar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Basic Operations

The document provides an overview of basic operations in programming, including arithmetic, logarithmic, and trigonometric functions, as well as vector initialization and manipulation. It also covers element-wise operations and matrix multiplication, demonstrating how to work with vectors and perform calculations. Additionally, it introduces the concept of exponential signals with imaginary powers and includes examples of plotting these signals.

Uploaded by

Muhammad Tarar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Basic Operations:

a=2;b=3;c=4; % Initialize some variables


a+b %Addition %ans = 5
a-b %Subtraction ans = -1 >> a*b %Multiplication ans = 6
a/b %Division %ans = 0.6667
a\b %Inverse %ans = 1.5000
a+b-a*c/a\b %ans = 0.5000
format short % Display only five Digits
pi %ans = 3.1416
format long % Display upto 15 Digits
pi %ans = 3.141592653589793
format rat % Replaces number by its closest rational number
pi %ans = 355/113
format short e % expresses numbers in power of 10
pi %ans = 3.1416e+00

sqrt(3) % get square root of given argument %ans = 1.7321


3^(1/2) % Evaluates number for any given power % ans = 1.7321
log(1000) %Natural Logarithm %ans = 6.9078

>> log10(1000) %Log to the base 10 ans = 3


cos(60*pi/180) %Trigonometric Functions are evaluated with arguments in
radians ans = 0.5000 >>acos(0.5) % Cosine inverse ans = 1.0472
floor(3.3) % Round Toward Negative Infinity ans = 3
ceil(4.23) % Round Toward Positive Infinity ans = 5
round(0.5) % Round to the nearest Integer or Decimal ans = 1
abs(1+i) % Evaluates magnitude of a complex number ans = 1.4142
angle(1+i)*180/pi %Evaluates Angular distance from '+x' axis for 2-D problems
%ans = 45

Introduction to Vectors and its Operation:


a=[1;2;3] %Initialize a 3-D vector
a=1
2
3
b=[4,5,6] %Initialize a row-vector
b=4
5
6
a' %Transpose of a vector %ans = 1 2 3
c=2*a %Multiplication by a scalar %c = 2 4 6
a+2* a % Addition of two vectors %ans = 3 6 9
sum(a) % Adds all elements of a vector %ans = 6
prod(b) %Multiply all elements %ans = 120
start = 0;
final = 1; increment = 0.2;
x = start: increment: final

%Ans: x = 0 0.2000 0.4000 0.6000 0.8000 1.0000;


• Element wise operation:

y = x.^2 %Each Element gets squared


y = 0 0.0400 0.1600 0.3600 0.6400 1.0000
c = y.*x %Element wise Multiplication
c = 0 0.0080 0.0640 0.2160 0.5120 1.0000
d = y./x %Element wise division
d = NaN 0.2000 0.4000 0.6000 0.8000 1.0000
e = y'*x %Matrix Multiplication
%e = 0 0 0 0 0 0 0 0.0080 0.0160 0.0240 0.0320 0.0400 0 0.0320 0.0640 0.0960
0.1280 0.1600 0 0.0720 0.1440 0.2160 0.2880 0.3600 0 0.1280 0.2560 0.3840
0.5120 0.6400 0 0.2000 0.4000 0.6000 0.8000 1.0000
f = y*x' % Matrix Multiplication f = 1.8000
length(x) %Count number of

Exponential signal with Imaginary power:


t = 0 : 0.001 : 20;
y1 = exp(-3*i*t); % Developing imaginary numerical model of simple decaying
exponential signal
plot3(t,real(y1),imag(y1)),title('f(t)=\ite^{-3jt}'); % plots negative frequency signal
y2 = exp(+3*i*t); % Developing imaginary numerical model of simple rising
exponential signal
plot3(t,real(y2),imag(y2)),title('f(t)=\ite^{3jt}'); % plots positive frequency signal

You might also like