You are on page 1of 12

MINISTERUL EDUCAIEI REPUBLICII MOLDOVA

UNIVERSITATEA TEHNIC A MOLDOVEI Facultatea Calculatoare, Informatic i Microelectronic FILIERA ANGLOFON

Catedra Mecanica teoretic

RAPORT
Lucrare de laborator nr. 2 la Mecanica teoretic

A efectuat:

st. gr. FAF-111 (l. englez)


A verificat:

ociug tefan

conf. univ.

Mircea Miglei

Chiinu 2011

LABORATORY WORK No. 2


I. Describe the basic commands used for building graphs in Matlab. II. Build the graphs of one variable functions on the given interval. Use "titles, axes writings, legend. Use different colors, styles of lines and markers. Prezent the graphs in the following methods: a) In different windows; b) In one window, and on the same axes; c) By using the 'subplot' command: c1) In one window, but on different axes:
Horizontal f(x) g(x) f(x) & g(x) Vertical Both on the axes from the right.

c2) In one window - each one apart on different axes and both on the same axes.
Both on the axes from the right. Both on the upper axes.

III. Build the graph of a two variable function on a dreptunghiular sector using different methods - mesh, surf, meshc, surfc, contour, contourf, contour3. Graph dimmensions will be chosen by itself.

Work processing Short Theory on laboratory work topic & methods used in laboratory work
The plot Instruction. The plot instruction in MATLAB is very versatile. It can be used to plot several different types of data. Its syntax is plot(x,y,' symbol and/or color') or plot(y,'symbol and/or color'). The instruction will plot a vector of data versus another vector of data. The first vector is referenced to the horizontal axis and the second to the vertical axis. If only one vector is used, then it is plotted with reference to the vertical axis while the horizontal axis is automatically forced to be the index of the vector for the corresponding data point. The notation inside the apostrophes is optionally used to designate whether each element of the vector is to be plotted as a single point with a certain symbol or as a curve with a straight line drawn between each data value. The colors can also be specified. Possible symbols are (*,o,+,.), and colors are (r,g,b,w) (red, green, blue, and white). Complex valued vectors are plotted by making the horizontal axis the real part of the vector and the vertical axis the imaginary part. Warning: A complex valued vector will automatically be plotted correctly on the complex plane (instead of real versus imaginary) only if every element of the vector is complex valued. Try plot (x,y,'*') , plot (x,'*'), plot (y,'*'), plot (y,x,'*') and plot (z,'*'), plot (Real (z), Imag (z),'*') to clarify your understanding of plot. Use

x=[1357],y=[2468],z=[1+j,2+2j,3+3j].

We may summarize as follows:

(red starpoints with the values of x on vertical and indicies on horizontal) (lineconnected curve of the value of y on vertical and plot(y) the value of x on horizontal) (lineconnected curve of the value of y on vertical and plot(x,y,'og') the value of x on horizontal) (circlepoints of the value of y on vertical and the value plot(x,y,'og') of x on horizontal) plot(real(z),imag(z)) (lineconnectedplot of z on the complex plane) plot(real(z),imag(z),'+b') (blue pluspoints of z on the complex plane).

plot(x,'*r')

Subplots. It is possible to split the graphics screen up into several separate smaller graphs rather than just one large graph. As many as four subplots can be created. The MATLAB instruction subplot (mnp) signifies which of the smaller graphs is to be accessed with the next plot statement. The mnp argument consists of three digits. The m and n are the numbers of rows (m) and columns (n) into which the screen should be divided. The pdesignates which of the matrix elements is to be used. For example,

Basic commands used for building graphs in Matlab. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10 . 11 . 12 . 13 . 14 . 15 . 16 . 17 . 18 . 19 . 20

The graph window figure(n) Prepares more windows to be filled with graphs. Figure deletion clf "Clear figure"-Deletes the figure, without resetting it's properties. clf reset Deletes the figure, with resetting it's properties. Building graph functions with one variable plot Builds a two dimensional graph. comet Builds the graph function in real time, we can see the function progression. Building graph functions with two variables plot3 3-D analog of the 'plot' function. mesh Surface sketch. surf
contour meshc, surfc contourf contour3 surfl meshgrid

Surface filled with color.


Plain graph with level lines. Surface with level lines in x,y plan. Graphic plan with colored level lines Surface composed from level lines. Lighten the surface. Creates a two variable matrix.

Graphs with their own axes subplot bar Shows more graphs on different axes in one window. Builds a bar graph.
4

. 21 . 22 . 23 . 24 . 25 .

Graph customizing title xlabel legend text Entitles the graph


Sets description on axes.

Describes the graph. Inserts text on the graph.

Text of the program in Matlab I. a)

x=-pi:4*pi; y1=(cos(x)).^2; plot(x,y1,'r--*') title('Functie de o variabila') xlabel('Axa X');ylabel('Axa Y') legend('Functia Y1') figure(2); x=-pi:4*pi; y2=log(abs(x)+1); plot(x,y2,'b-.+') title('Functie de o variabila') xlabel('Axa X');ylabel('Axa Y') legend('Functia Y2')

b)

x=-pi:4*pi; x1=-pi:4*pi; y1=(cos(x)).^2; y2=log(abs(x)+1); figure(3); hold on plot(x,y1,'b--+'); plot(x1,y2,'r-.*'); title('Grafic cu axe comune') xlabel('Axa X');ylabel('Axa Y') legend('Functia Y1','Functia Y2')

c1)

x=-pi:4*pi; x1=-pi:4*pi; y1=(cos(x)).^2; y2=log(abs(x)+1); figure(4); subplot(3,1,1); plot(x,y1,'b--+'); title('Grafic-Functia "cosinus"') xlabel('Axa X');ylabel('Axa Y') legend('Functia Y1'); subplot(3,1,2); plot(x1,y2,'r-.*'); title('Grafic-Functia "ln"') xlabel('Axa X');ylabel('Axa Y') legend('Functia Y2'); subplot(3,1,3); hold on; plot(x,y1,'b--+'); plot(x1,y2,'r-.*'); title('Grafic mixt') xlabel('Axa X');ylabel('Axa Y') legend('Functia Y1','Functia Y2') 6

c1')

x=-pi:4*pi; x1=-pi:4*pi; y1=(cos(x)).^2; y2=log(abs(x)+1); figure(4); subplot(1,3,1); plot(x,y1,'b--+'); title('Grafic-Functia "cosinus"') xlabel('Axa X');ylabel('Axa Y') legend('Functia Y1'); subplot(1,3,2); plot(x1,y2,'r-.*'); title('Grafic-Functia "ln"') xlabel('Axa X');ylabel('Axa Y') legend('Functia Y2'); subplot(1,3,3); hold on; plot(x,y1,'b--+'); plot(x1,y2,'r-.*'); title('Grafic mixt') xlabel('Axa X');ylabel('Axa Y') legend('Functia Y1','Functia Y2')

c2)

x=-pi:4*pi; x1=-pi:4*pi; y1=(cos(x)).^2; y2=log(abs(x)+1); figure(4); subplot(2,2,1) plot(x,y1,'b--+'); title('Grafic-Functia "cosinus"') xlabel('Axa X');ylabel('Axa Y') legend('Functia Y1'); subplot(2,2,3); plot(x1,y2,'r-.*'); title('Grafic-Functia "ln"') xlabel('Axa X');ylabel('Axa Y') legend('Functia Y2'); subplot(2,2,[2,4]); hold on; plot(x,y1,'b--+'); plot(x1,y2,'r-.*'); title('Grafic mixt') xlabel('Axa X');ylabel('Axa Y') legend('Functia Y1','Functia Y2')

c2')

x=-pi:4*pi; x1=-pi:4*pi; y1=(cos(x)).^2; y2=log(abs(x)+1); figure(4); subplot(2,2,3) plot(x,y1,'b--+'); title('Grafic-Functia "cosinus"') xlabel('Axa X');ylabel('Axa Y') 7

legend('Functia Y1'); subplot(2,2,4); plot(x1,y2,'r-.*'); title('Grafic-Functia "ln"') xlabel('Axa X');ylabel('Axa Y') legend('Functia Y2'); subplot(2,2,[1,2]); hold on; plot(x,y1,'b--+'); plot(x1,y2,'r-.*'); title('Grafic mixt') xlabel('Axa X');ylabel('Axa Y') legend('Functia Y1','Functia Y2')

II.
[x,y]=meshgrid(-1:0.1:1,-pi:0.1:pi) z=exp(-abs(x)).*(cos(x-y)).^2; mesh(x,y,z); figure(2); surf(x,y,z); figure(3); meshc(x,y,z); figure(4); surfc(x,y,z); figure(5); contour(x,y,z); figure(6); contourf(x,y,z); figure(7); contour3(x,y,z);

Results and there verification


8

The following are the graphs obtained as result of program computation.

I. a)
Functie de o variabila 1 Functia Y1 0.9 0.8 0.7 2 0.6 Axa Y 0.5 0.4 0.3 0.2 0.5 0.1 0 -4 0 -4 1 Axa Y 1.5 2.5 3 Functia Y2 Functie de o variabila

-2

4 Axa X

10

12

-2

4 Axa X

10

12

b)
Grafic cu axe comune 3 Axa Y Functia Y1 Functia Y2 2.5

c1)
Grafic-Functia "cosinus" 1 Functia Y1 0.5 0 -4 -2 0 2 4 6 Axa X Grafic-Functia "ln" 8 10 12

2 4 Axa Y Axa Y

Functia Y2 2 0 -4 -2 0 2 4 Axa X Grafic mixt 6 8 10 12

1.5

1 4 Axa Y 0.5 2 0 -4 -2 0 2 4 Axa X 6 8 10 12 -2 0 2

Functia Y1 Functia Y2 4 Axa X 6 8 10 12

0 -4

c1')
9

c2)

Grafic-Functia "cosinus" 1 Functia Y1 0.9 0.8 0.7

Grafic-Functia "ln" 3 Functia Y2 2.5 2.5 3

Grafic mixt 1 Functia Y1 Functia Y2 Axa Y 0.5

Grafic-Functia "cosinus" 3 Functia Y1 2.5

Grafic mixt Functia Y1 Functia Y2

2 0.6 Axa Y Axa Y 0.5 0.4 0.3 0.2 0.5 0.1 0 -20 0 -20 1 1.5 Axa Y

2 0 -5 1.5 3 1 2 0.5 Axa Y Functia Y2 5 10 Axa X Grafic-Functia "ln" 0 15

Axa Y

1.5

0.5

0 Axa X

20

0 Axa X

20

0 -20

0 Axa X

20

0 -5

5 Axa X

10

15

0 -5

5 Axa X

10

15

c2')
Grafic mixt 3 Functia Y1 Functia Y2

2 Axa Y

0 -4

-2

4 Axa X 3

10

12

Grafic-Functia "cosinus" 1 Functia Y1 2 0.5 Axa Y Axa Y

Grafic-Functia "ln" Functia Y2

0 -5

5 Axa X

10

15

0 -5

5 Axa X

10

15

II.
10

Figure(1)

Figure(2)

1 1 0.8 0.8 0.6 0.6 0.4 0.4 0.2 0.2 0 4 2 0 -2 -4 -1 0 -0.5 0.5 1 0 4 2 0 -2 -4 -1 0 -0.5 0.5 1

Figure(3)

Figure(4)

1 1 0.8 0.8 0.6 0.6 0.4 0.4 0.2 0.2 0 4 2 0 -2 -4 -1 0 -0.5 0.5 1 0 4 2 0 -2 -4 -1 0 -0.5 0.5 1

-1

Figure(5)
11
-0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1

-1

Figure(6)

-2

-2

-3 -1

-3 -1

-0.8

-0.6

-0.4

-0.2

0.2

0.4

0.6

0.8

Figure(7)
1 0.8 0.6 0.4 0.2 0 2 0 0 -2 -1 -0.5 0.5 1

Conclusion
On this laboratory work i had the oportunity to experience Matlab graph functions in use. Despite the fact that Matlab has a very simple programming language, it has a powerful core of computing mathematic equations, and graphs. So, learning them well now, may serve us well in the future solving of different problems and program making. Organazing the report, presenting results, is an important step forward forming us as engineers.

Bibliography
1. http://www.mathworks.com

12

You might also like