FAMILIARIZATION OF SCIENTIFIC COMPUTING

 

OBJECTIVE

·  To familiarize different functions for scientific computing with examples 

LEARNING OUTCOMES

·  After the completion of this experiment students will be able to execute small scripts using different arithmetic functions 

SOFTWARE USED:

                 MATLAB® R2017a

THEORY

The different arithmetic functions of MATLAB are listed below.

Y = abs(X) returns the absolute value of each element in array X. If X is complex, abs(X) returns the complex magnitude.

abs - Absolute value and complex magnitude

angle- Phase angle

complex- Create complex array

isreal- whether array is real

real- Real part of complex number

sinc – returns an array, y, whose elements are the sinc of the elements of the input, x.

imag - Imaginary Part of Complex Number

sin – Sine of argument in radians

cos - cos of argument in radians

1. Type the following in the command window, write down the results and the functions of these built in modules

(a) 2.15e-3

(b) mod(5,3)

(c) floor(3.5)

(d) ceil(3.6)

(e) round(3.4)

(f) Create a one dimensional array of ones having size 5

(g) Create a one dimensional array of zeros having size 5

(h) Create a 3x2 matrix ‘K’ having only zeros

2.  Generate the following output using the function ‘abs’

(a)  

                                                                 

(b)



(c)


PROGRAM

(a)

x=[-3:0.1:3];

y=abs(x);

plot(x,y)

xlabel('x');

ylabel('y');

(b)

x=[-3:0.1:3];

y=-abs(x);

plot(x,y)

xlabel('x');

ylabel('y');


(c)

x=[-3:0.1:3];

y=abs(x);

plot(x,y)

hold on;

y=-abs(x);

plot(x,y);

hold off;

xlabel('x');

ylabel('y');

3. Create a complex number 5+4i, extract the real and imaginary parts and compute the magnitude of the vector using built in functions

PROGRAM

z=complex(5,4);

disp('Real Part');

a=real(z)

disp('Imaginary Part');

b=imag(z)

disp('Magnitude');

abs(z)

OUTPUT

Real Part

a =     5

Imaginary Part

b =  4

Magnitude

ans =6.4031

4.  Represent the complex exponential form  as rectangular form and find the real part, magnitude and the angle of the vector (both in degree and radians).

PROGRAM

z=exp(pi*i);

disp('Complex number in rectangular form');

z

disp('Real Part');

a=real(z)

disp('Magnitude');

mag=abs(z)

disp('Angle in radians');

ang=angle(z)

disp('Angle in degree');

ang_deg=ang*(180/pi)

OUTPUT

Complex number in rectangular form

z = -1.0000 + 0.0000i

Real Part

a = -1

Magnitude

mag =1

Angle in radians

ang =3.1416

Angle in degree

ang_deg =180

5.  Plot the following

(a) 


(b)

(c)
                                                       
                  

PROGRAM

(a)

x=[-5:0.001:5];

y=sinc(x);

plot(x,y)

(b)

t=-9:0.01:9;

y=sin(t);

x=cos(t);

plot(x,y)

(c)

t=0:0.001:1

y=exp(-5*t);

plot(t,y);


5. Plot sinewaves of frequency 50 and 100 Hz on the same figure window.

PROGRAM

f=50;

t=0:0.0002:0.1;

y=sin(2*pi*f*t);

plot(t,y);

grid on;

hold on;

f=100;

t=0:0.0002:0.1;

y=sin(2*pi*f*t);

plot(t,y);

hold off;

OUTPUT 


6. Replace the given code with vectorized code for fast computing

(a)

This code computes the sine of 1,001 values ranging from 0 to 10:

clc;

clear all;

close all;

i = 0;

for t = 0:.01:10

    i = i + 1;

    y(i) = sin(t);

end

disp(y);

 

(b)

clc;

clear all;

close all;

r=[1:4];

h=[1:4];

for i=1:4

volume(i) = pi*r(i)*r(i)*h(i);

end

disp(volume);

 PROGRAM

(a)

t = 0:.01:10;

y = sin(t);

disp(y);

 (b)

clc;

clear all;

close all;

r=[1:4];

h=[1:4];

volume = pi*r.^2.*h;

disp(volume);

OUTPUT

[3.1416   25.1327   84.8230  201.0619]

7. Execute a script (.m file) to obtain the dot product and the cross product of two vectors a and b, where a = (1 5 6) and b = (2 3 8).

PROGRAM

a = [1 5 6];

b = [2 3 8];

d=dot(a,b)

c=cross(a,b)

OUTPUT

d =65

c = 22     4    -7

 

8. Simplify the expression and express the complex number in rectangular and polar form

(a) 


(b)

(a) PROGRAM

clc;

clear all;

close all;

Z1 = 0.5;

Z2 =6*j;

Z3 = 3.5*exp(j*0.6);

Z4 = 3+6*j;

Z5 = exp(j*0.3*pi);

disp('Z in rectangular form is');

Z_rect = Z1+Z2+Z3+(Z4*Z5);

Z_rect

Z_mag = abs (Z_rect); % magnitude of Z

Z_angle = angle(Z_rect)*(180/pi); % Angle in degrees

disp('complex number Z in polar form, mag, phase');

Z_polar = [Z_mag, Z_angle]

OUTPUT

Z in rectangular form is

Z_rect =0.2979 +13.9300i

complex number Z in polar form, mag, phase

Z_polar =13.9332   88.7748

(b) PROGRAM

clc;

clear all;

close all;

Z1 = 3+4*j;

Z2 = 5+2*j;

theta = 60*(pi/180); % angle in radians

Z3 = 2*exp(j*theta);

Z4 = 3+6*j;

Z5 = 1+2*j;

disp('Z in rectangular form is');

Z_rect = Z1*Z2*Z3/(Z4*Z5);

Z_rect

Z_mag = abs (Z_rect); % magnitude of Z

Z_angle = angle(Z_rect)*(180/pi); % Angle in degrees

disp('complex number Z in polar form, mag, phase');

Z_polar = [Z_mag, Z_angle]

OUTPUT

Z in rectangular form is

Z_rect =3.5546 + 0.5035i

complex number Z in polar form, mag, phase

Z_polar = 3.5901    8.0616

9. The voltage across a capacitor is 

Plot voltage v (t), versus time, t, for t = 0 to 50 seconds with increment of 5 s. Do not use loops.

PROGRAM

clc;

clear all;

close all;

t=0:5:50

v=10*(1-exp(-0.2*t));

plot(t,v)

xlabel('Time')

ylabel('Voltage')

OUTPUT



INFERENCE:

Familiarized with basic arithmetic functions for scientific computing and used vectorized computing for fast scientific applications.

Comments

Popular posts from this blog

Coin Toss and Level crossing problem