Presentation is loading. Please wait.

Presentation is loading. Please wait.

EGR 115 Introduction to Computing for Engineers Complex Numbers & 3D Plots – Part 2 Friday 07 Nov 2014 EGR 115 Introduction to Computing for Engineers.

Similar presentations


Presentation on theme: "EGR 115 Introduction to Computing for Engineers Complex Numbers & 3D Plots – Part 2 Friday 07 Nov 2014 EGR 115 Introduction to Computing for Engineers."— Presentation transcript:

1 EGR 115 Introduction to Computing for Engineers Complex Numbers & 3D Plots – Part 2 Friday 07 Nov 2014 EGR 115 Introduction to Computing for Engineers

2 Lecture Outline Friday 07 Nov 2014 EGR 115 Introduction to Computing for Engineers Multi-Dimensional Arrays and 3D Plots  Multi-Dimensional arrays  A Variety of 3D plotting functions Slide 2 of 14

3 Multi-Dimensional arrays Friday 07 Nov 2014 EGR 115 Introduction to Computing for Engineers A row/col vector => A 1-dimensional array A Matrix => A 2-dimensional array  Size of (a) is: 2 X 4 A Multi-Dimensional array:  Size of (b) is: 2 X 4 X 3 % A matrix (2-dim array) a = [1 2 3 4; 5 6 7 8]; % A multi-dimensional array b(:,:,1) = a; b(:,:,2) = 2*a; b(:,:,3) = [ -1 -2 -3 4; 0 3 2 9]; Slide 3 of 14

4 Multi-Dimensional arrays Friday 07 Nov 2014 EGR 115 Introduction to Computing for Engineers What is the value of:  b(2,2,2)?  b(:,:,1) ? = a  b(1,2,3)? Can provide a convenient way to store an array of matrices  E.g., rand(3,3,6); or zeros(5,6,20); or ones(1,2,4); % A multi-dim array b(:,:,1) = a; b(:,:,2) = 2*a; b(:,:,3) = [ -1 -2 -3 4; 0 3 2 9]; % A matrix (2-dim array) a = [1 2 3 4; 5 6 7 8]; Slide 4 of 14

5 Three Dimensional Plots Friday 07 Nov 2014 EGR 115 Introduction to Computing for Engineers One of the key features of MATLAB is the ease of which plots/figures are produced This is especially true for three dimensional plots which are especially convenient in the MATLAB environment Three dimensional plots can be categorized into:  Line plots -> plot3  Mesh plots -> mesh  Surface plots -> surf  Contour plots -> contour  Additional 3D plots Slide 5 of 14

6 Three Dimensional Plots The Plot3 Function Friday 07 Nov 2014 EGR 115 Introduction to Computing for Engineers The plot3() function Use the Rotate 3D icon in the plot window % A Plot3 Example z = 0:.1:10; x = exp(-0.2*z).* cos(2*z); y = exp(-0.2*z).* sin(2*z); plot3(x, y, z, 'r', 'LineWidth', 3) xlabel('x-axis'); ylabel('y-axis'); zlabel('z-axis') title('EGR115: A 3D Line Plot') grid Slide 6 of 14 MATLAB Code

7 Three Dimensional Plots The Plot3 Function Friday 07 Nov 2014 EGR 115 Introduction to Computing for Engineers An In-class example:  Plot the following coordinates of a UAV in flight: o x = cost(t), y = sin(t), and z = sin(5*t)  For 0 ≤ t ≤  Slide 7 of 14

8 Three Dimensional Plots The Mesh Plot Function Friday 07 Nov 2014 EGR 115 Introduction to Computing for Engineers Creates a mesh or wireframe plot of arguments  Effectively plots a matrix where x/y coordinates are row/col indices and z is the value stored at the row/col address. o E.g., mesh(z) % A Mesh 3D Example my_grid = [ 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 1 2 2 2 1 0 0 1 2 3 2 1 0 0 1 2 2 2 1 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0]; figure, mesh(my_grid,'LineWidth',2); Slide 8 of 14 MATLAB Code

9 Three Dimensional Plots The Mesh Plot Function Friday 07 Nov 2014 EGR 115 Introduction to Computing for Engineers A more sophisticated example: The 3D sinc function  E.g., mesh(x, y, z) % The 3D Sinc Function [X,Y] = meshgrid(-10:.5:10); R = sqrt(X.^2 + Y.^2) + eps; Z = sin(R)./R; figure, mesh(X,Y,Z) xlabel('x-axis'); ylabel('y-axis'); zlabel('z-axis') title('The 3D Sinc Function') NOTE: Now x, y, and z are all matrices of the same size Slide 9 of 14 MATLAB Code Look at: mesh(X) and mesh(Y)

10 Three Dimensional Plots The Surface Plot Friday 07 Nov 2014 EGR 115 Introduction to Computing for Engineers A more sophisticated example: The 3D sinc function  E.g., surf(x, y, z) % The 3D Sinc Function [X,Y] = meshgrid(-10:.5:10); R = sqrt(X.^2 + Y.^2) + eps; Z = sin(R)./R; figure, surf(X,Y,Z) xlabel('x-axis'); ylabel('y-axis'); zlabel('z-axis') title('The 3D Sinc Function') NOTE: Very similar to the mesh plot Slide 10 of 14 MATLAB Code

11 Three Dimensional Plots The Friday 07 Nov 2014 EGR 115 Introduction to Computing for Engineers A more sophisticated example: The 3D sinc function  E.g., contour (x, y, z) % The 3D Sinc Function [X,Y] = meshgrid(-10:.5:10); R = sqrt(X.^2 + Y.^2) + eps; Z = sin(R)./R; figure, contour(X,Y,Z) xlabel('x-axis'); ylabel('y-axis'); zlabel('z-axis') title('The 3D Sinc Function') Think of topo-map height contour lines Slide 11 of 14 MATLAB Code

12 Three Dimensional Plots Other 3D Plotting Functions Friday 07 Nov 2014 EGR 115 Introduction to Computing for Engineers More 3D Plotting Functions:  stem3 – height at an x, y coordinate Plot the following coordinates of a UAV in flight:  x = cost(t), y = sin(t), and z = sin(5*t) o For 0 ≤ t ≤  % The 3D stem3 Function t = 0:0.05:pi; x = cos(t); y = sin(t); z = sin(5*t); figure, stem3(x, y, z, 'r') Slide 12 of 14 MATLAB Code

13 Three Dimensional Plots Other 3D Plotting Functions Friday 07 Nov 2014 EGR 115 Introduction to Computing for Engineers Another stem3 example % The 3D stem3 Function my_grid = [ 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 1 2 2 2 1 0 0 1 2 3 2 1 0 0 1 2 2 2 1 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0]; figure, stem3(my_grid,'LineWidth',2); Slide 13 of 14 MATLAB Code

14 Next Lecture Friday 07 Nov 2014 EGR 115 Introduction to Computing for Engineers More 3D Plotting Slide 14 of 14


Download ppt "EGR 115 Introduction to Computing for Engineers Complex Numbers & 3D Plots – Part 2 Friday 07 Nov 2014 EGR 115 Introduction to Computing for Engineers."

Similar presentations


Ads by Google