MATLAB MANUAL FOR NANO SCIENTISTS

22
[Type text] KUVEMPU UNIVERSITY As per syllabus of MTech. In Nano Science and Technology Published in 2011 SRIKANTH H P MANUAL FOR NANO SCIENTISTS

description

Covering 17 simple experiments ,best toilered for a interdisciplinary and multidisciplinary courses.This manual is so simple with simple experiments,may become "must haves" for any Tom ,Dick and Harry not knowing an iota of MATLAB a thirst for simulation techniques in nanotechnology.

Transcript of MATLAB MANUAL FOR NANO SCIENTISTS

Page 1: MATLAB MANUAL FOR NANO SCIENTISTS

[Type text]

[Type text]

KUVEMPU UNIVERSITY

As per syllabus of MTech. In Nano Science

and Technology

P u b l i s h e d i n 2 0 1 1

MANUAL FOR MATLAB

Fully covered topics of MATLAB with the latest R2011a

series of Student Version compatibility that meets the

needs of 1st Year Master’s Degree of Nano Science and

Technology.

SRIKANTH H P

MANUAL FOR NANO SCIENTISTS

Page 2: MATLAB MANUAL FOR NANO SCIENTISTS

1

Contents

PREFACE: ................................................................................................................................................. 2

1. Write a program to perform addition of n numbers Output .......................................................... 3

2. Write a program to demonstrate multiple plots in a single graph. ................................................ 4

3 . Write a program to demonstrate subplots . .................................................................................. 5

4. Write a program to demonstrate the 7th order approximation equation. .................................... 6

5. Write a program to plot bar chart for world population readings. ................................................ 7

6. Write a program to plot pie chart for world population readings. ................................................. 8

7. Write a program to demonstrate relational operators using switch Output………………………………9

8. Write a program to find if the number is even or odd Output ..................................................... 10

9. Write a program to plot ideal gas response. ................................................................................ 11

10. Write a program to demonstrate carbon dating Output .............................................................. 12

11. Write a program to demonstrate the maximum power transfer theorem. ................................. 13

12. Write a program to swap two numbers Output ........................................................................... 14

13. Write a program to plot the energy Eigen values of a one dimensional box Output ................... 16

14. Write a program to determine the resistance of resistors in series Output ................................ 17

15. Write a program to find the sum of squares of two numbers Output ......................................... 18

16. Write a program to find the area of triangle Output .................................................................... 19

17. Write a program to determine the area of a circle Output .......................................................... 20

Page 3: MATLAB MANUAL FOR NANO SCIENTISTS

2

PREFACE:

In the preamble to nanotechnology, we come across a wide description of simulation

techniques, sans which there lie a world of experimental chemists and theoretical

physics. I had a stress on tough proactive practicals using MATLAB but there was a

lacuna I felt that needed less emphasis since there is no actual outcome of quantum

mechanical description of nanoparticals. So in order to extrapolate the subject, we

were being taught chemistry and physics of matter. Hence there was a space for me

to put this materials to show the various computation techniques for an

interdisciplinary user and at the same time incorporate some basics of chemistry and

physics in problem solving which I presume the student undertaking nanotechnology

or material science also has similar background of subjects like maths, physics and

chemistry.

- Srikanth H P

Page 4: MATLAB MANUAL FOR NANO SCIENTISTS

3

1. Write a program to perform addition of n numbers.

n=input('How many numbers do you want to add? '); a=0; for i=1:n fprintf('enter the %i value ',i); a(i)=input(''); end total=sum(a); disp('The sum of numbers is') disp(total);

Output How many numbers do you want to add? 4

enter the 1 value 4

enter the 2 value 5

enter the 3 value 6

enter the 4 value 7

The sum of numbers is

22

Page 5: MATLAB MANUAL FOR NANO SCIENTISTS

4

2. Write a program to demonstrate multiple plots in a single graph.

x=-pi:pi/20:pi; y1=sin(x); y2=cos(x); plot(x,y1,'*'); hold on; plot(x,y2,'r--'); hold on; legend('sin x','cos x');

-4 -3 -2 -1 0 1 2 3 4-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

sin x

cos x

Page 6: MATLAB MANUAL FOR NANO SCIENTISTS

5

3 . Write a program to demonstrate subplots .

figure(1) subplot(2,1,1) x=-pi:pi/20:pi; y=sin(x); plot(x,y) title('subplot 1 title'); subplot(2,1,2) x=-pi:pi/20:pi; y=cos(x); plot(x,y); title('subplot 2 title')

-4 -3 -2 -1 0 1 2 3 4-1

-0.5

0

0.5

1subplot 1 title

-4 -3 -2 -1 0 1 2 3 4-1

-0.5

0

0.5

1subplot 2 title

Page 7: MATLAB MANUAL FOR NANO SCIENTISTS

6

4. Write a program to demonstrate the 7th order approximation

equation. ( ) ( ) ( )

( )

t=linspace(0,2*pi,100); y1=sin(t); y2=t; y3=t-(t.^3)/6+(t.^5)/120-(t.^7)/5040; plot(t,y1) line(t,y2,'linestyle','--') line(t,y3,'marker','o') axis([0 5 -1 5]) xlabel('t') ylabel('sin(t) approximation') title('sin(t) function') legend('sin(t)','line approx','7th order approx')

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-1

0

1

2

3

4

5

t

sin

(t)

appro

xim

ation

sin(t) function

sin(t)

line approx

7th order approx

Page 8: MATLAB MANUAL FOR NANO SCIENTISTS

7

5. Write a program to plot bar chart for world population readings.

cont=char('China','India','UnitedStates','Indonesia','Brazil','Bangladesh',

'Nigeria','Russia','Japan'); pop=[133;116;30;24;19;17;15;14;14;12]; bar(pop); xlabel('Major countries'); ylabel('population in crores'); title('world popuation in 2011');

for i=1:5:gtext(cont(i)) end

1 2 3 4 5 6 7 8 9 100

20

40

60

80

100

120

140

Major countries

popula

tion in c

rore

s

world popuation in 2011

Page 9: MATLAB MANUAL FOR NANO SCIENTISTS

8

6. Write a program to plot pie chart for world population readings.

cont=char('China','India','UnitedStates','Indonesia','Brazil','Bangladesh',

'Nigeria','Russia','Japan'); pop=[133;116;30;24;19;17;15;14;14;12]; pie(pop); title('world population in 2011'); for i=1:5:gtext(cont(i)); end

34%

29%

8%

6%

5%

4%

4%

4%

4%3%

world population in 2011

Page 10: MATLAB MANUAL FOR NANO SCIENTISTS

9

7. Write a program to demonstrate relational operators using

switch.

a=input('Enter the first number --->a='); b=input('Enter the second number--->b='); x=input('Enter the choice in between 1 to 3 so as to find equal, greater

and lesser--->'); switch x case 1 if a==b disp('the numbers are equal'); else disp('the numbers are not equal'); end case 2 if a>b disp('the number a is greater than b'); else disp('the number b is greater than a'); end case 3 if a<b disp('the number a is less than b'); else disp('the number b is less than a'); end otherwise disp('please choose values between 1 and 3') end

Output Enter the first number --->2

Enter the second number--->4

Enter the choice in between 1 to 3 so as to find equal,greater and lesser--->2

the number b is greater than a

Enter the first number --->a=2

Enter the second number--->b=4

Enter the choice in between 1 to 3 so as to find equal,greater ans lesser--->3

the number a is less then b

>>

Page 11: MATLAB MANUAL FOR NANO SCIENTISTS

10

8. Write a program to find if the number is even or odd.

a=input('Enter the number to know if even-->a='); c=2; b=rem(a,c); if b==0 disp('The number a is even'); else disp('The number a is odd'); end

Output Enter the number to know if even-->a=22

The number a is even

Page 12: MATLAB MANUAL FOR NANO SCIENTISTS

11

9. Write a program to plot ideal gas response.

n=1; r=8.314; t=273; p=1:0.1:1000; v=(n*r*t)./p; figure(1); loglog(p,v,'r-','linewidth',2); title('\bf volume vs pressure in ideal gas'); xlabel('\bf pressure(kpa)'); ylabel('\bf volume (m^3)'); hold on; grid on; t=373; v=(n*r*t)./p; figure(1); loglog(p,v,'b-','linewidth',2); hold on; t=473; v=(n*r*t)./p; figure(1); loglog(p,v,'g-','linewidth',2); hold off;

100

101

102

103

100

101

102

103

104

volume vs pressure in ideal gas

pressure(kpa)

vo

lum

e (

m3)

Page 13: MATLAB MANUAL FOR NANO SCIENTISTS

12

10. Write a program to demonstrate carbon dating.

lamda=0.00012097; percent=input('Enter the percentage of carbon 14 remaining:\n'); ratio=percent/100; age=(-1.0/lamda)*log(ratio); string=['The age of sample is ',num2str(age),' years ']; disp(string);

Output Enter the percentage of carbon 14 remaining:

78

The age of sample is 2053.9089 years

Page 14: MATLAB MANUAL FOR NANO SCIENTISTS

13

11. Write a program to demonstrate the maximum power

transfer theorem.

volts=120; rs=50; r1=1:1:100; amps=volts./(rs+r1); p1=(amps.^2).*r1; plot(r1,p1); title('Plot of power vs load resistance'); xlabel('Load resistance(ohms)'); ylabel('Power(watts)'); grid on;

0 10 20 30 40 50 60 70 80 90 1000

10

20

30

40

50

60

70

80plot of power vs load resistance

load resistance(ohms)

pow

er(

watt

s)

Page 15: MATLAB MANUAL FOR NANO SCIENTISTS

14

12. Write a program to swap two numbers.

a=input('enter the a value'); b=input('enter the b value'); a=a+b; b=a-b; a=a-b; fprintf('after the swapping the value of a is %i\n',a); fprintf('after the swapping the value of b is %i\n',b);

Output enter the a value 12

enter the b value 23

after the swapping the value of a is 23

after the swapping the value of b is 12

Page 16: MATLAB MANUAL FOR NANO SCIENTISTS

15

13. Write a program to plot the energy Eigen values of a one

dimensional box.

L=10e-9; d=200; x=0:L/d:L; m=9.1e-31; num_sol=4; h=6.624e-34; for j=1:num_sol e(j)=((j*j))*((h*h)/(8*m*L*L)); fprintf(' The energy of energy level n=%i value is ',j); fprintf('%i joules \n',e(j)); end;

figure(1);

subplot(4,1,1); w4=((2/L)^.5)*(sin((4*pi*x)/L)); plot(x,w4); xlabel(' 0 < n < L'); ylabel('Asin(\Theta4)'); title('Plot of Asin(\Theta4) for n=4');

subplot(4,1,2); w3=((2/L)^.5)*(cos((3*pi*x)/L)); plot(x,w3); xlabel(' 0 < n < L'); ylabel('Acos(\Theta3)'); title('Plot of Acos(\Theta3) for n=3');

subplot(4,1,3); w2=((2/L)^.5)*(sin((2*pi*x)/L)); plot(x,w2); xlabel(' 0 < n < L'); ylabel('Asin(\Theta2)'); title('Plot of Asin(\Theta2) for n=2');

subplot(4,1,4); w1=((2/L)^.5)*(cos((pi*x)/L)); plot(x,w1); xlabel(' 0 < n < L '); ylabel('Acos(\Theta1)'); title('Plot of Acos(\Theta1) for n=1');

Page 17: MATLAB MANUAL FOR NANO SCIENTISTS

16

Output The energy of energy level n=1 value is 6.027112e-022 joules

The energy of energy level n=2 value is 2.410845e-021 joules

The energy of energy level n=3 value is 5.424401e-021 joules

The energy of energy level n=4 value is 9.643379e-021 joules

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

x 10-8

-2

0

2x 10

4

0 < n < L

Asin

( 4)

Plot of Asin(4) for n=4

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

x 10-8

-2

0

2x 10

4

0 < n < L

Acos(

3)

Plot of Acos(3) for n=3

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

x 10-8

-2

0

2x 10

4

0 < n < L

Asin

( 2)

Plot of Asin(2) for n=2

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

x 10-8

-2

0

2x 10

4

0 < n < L

Acos(

1)

Plot of Acos(1) for n=1

Page 18: MATLAB MANUAL FOR NANO SCIENTISTS

17

14. Write a program to determine the resistance of resistors in

series.

vs=input('Enter the source voltage V='); rn=input('Enter the voltage of resistors as elements in a row vector '); req=sum(rn); vn=rn*vs/req; i=vs/req;

pn=vn*i; ptotal=vs*i; table=[rn',vn',pn']; disp('Resistance Voltage Power'); disp('(ohms) (volts) (watts)'); disp(table); fprintf('The current in the circuit is %f amp ',i); fprintf('\n The total power dissipated in the circuit is %f

watts\n',ptotal);

Output Enter the source voltage V= 230

Enter the voltage of resistors as elements in a row vector [12 23 45 56]

Resistance Voltage Power

(ohms) (volts) (watts)

12.0000 20.2941 34.3209

23.0000 38.8971 65.7818

45.0000 76.1029 128.7035

56.0000 94.7059 160.1644

The current in the circuit is 1.691176 amp

The total power dissipated in the circuit is 388.970588 watts

Page 19: MATLAB MANUAL FOR NANO SCIENTISTS

18

15. Write a program to find the sum of squares of two

numbers .

a=input('Enter the value of a'); b=input('Enter the value of b'); %sum is c=a^2+b^2;

fprintf('The sum of squares is %i\n',c);

Output Enter the value of a 23

Enter the value of b 34

The sum of squares is 1685

Page 20: MATLAB MANUAL FOR NANO SCIENTISTS

19

16. Write a program to find the area of triangle.

h=input('Enter the value of height h='); b=input('Enter the value of base b='); %area of triangle is area=b*h/2; fprintf('The area of the triangle with base b and height h is %i\n ',area);

Output Enter the value of height h= 34

Enter the value of base b= 34

The area of the triangle with base b and height h is 578

Page 21: MATLAB MANUAL FOR NANO SCIENTISTS

20

17. Write a program to determine the area of a circle.

r=input('Enter the value of radius of the circle--->r='); area=pi*r*r; string=['The area of the circle with radius r is area=',num2str(area),'

Square units ']; disp(string);

Output Enter the value of radius of the circle--->r=76

The area of the circle with radius r is area=18145.8392 Square units

Page 22: MATLAB MANUAL FOR NANO SCIENTISTS

21

About the Author:

Srikanth H P is holding an MTech. in Nanotechnology from Kuvempu

University and a B.E in Electronics and Communication Engineering from

Vemana Institute of Technology ( Affiliated to VTU). He had previously

worked with Dr. Preeta Sharan to publish a lab manual on Analog and Digital

Communication lab. He currently has one national and one international conference papers. He also

has a PG Diploma in Performing arts from Kuvempu University and a number of training certificates

for various courses of industrial importance. He is a member of IEEE (and UFFC) as a student

member and life member of Indian Physical Society, Indian Physics Association, Institution of

Engineers and Indian Society for technical Education.