<< Chapter < Page Chapter >> Page >

Note that the above script clears the command window and variable workspace. It also closes any open Figures. After running the script, we will have X1, Y1, Y2, Y3 and Y4 loaded in the workspace. Next, select File>New>Figure, a new Figure window will open. Click "Show Plot Tools and Dock Figure" on the tool bar.

PlotTools
Plot Tools

Under New Subplots>2D Axes, select four vertical boxes that will create four subplots in one figure. Also notice, the five variables we created earlier are listed under Variables.

Plot Tools
Creating four sub plots.

After the subplots have been created, select the first supblot and click on "Add Data". In the dialog box, set X Data Source to X1 and Y Data Source to Y1. Repeat this step for the remaining subplots paying attention to Y Data Source (Y2, Y3 and Y4 need to be selected in the subsequent steps while X1 is always the X Data Source).

PlotTools
Adding data to axes.

Next, select the first item in "Plot Browser" and activate the "Property Editor". Fill out the fields as shown in the figure below. Repeat this step for all subplots.

PlotTools
Using "Property Editor".

Save the figure as sinxcosx.fig in the current directory.

PlotTools
The four subplots generated with "Plot Tools".

SubPlot
The four subplots in a single figure.

Three-dimensional plots

3D plots can be generated from the Command Window as well as by GUI alternatives. This time, we will go back to the Command Window.

The plot3 Statement

With the X1,Y1,Y2 and Y2 variables still in the workspace, type in plot3(X1,Y1,Y2) at the MATLAB prompt. A figure will be generated, click "Show Plot Tools and Dock Figure".

Plot
A raw 3D figure is generated with plot3 .

Use the property editor to make the following changes.

Plot
3D Property Editor.

The final result should look like this:

Plot
3D graph of x, sin(x), cos(x)

Use help or doc commands to learn more about 3D plots, for example, image(x) , surf(x) and mesh(x) .

Quiver or velocity plots

To plot vectors, it is useful to draw arrows so that the direction of the arrow points the direction of the vector and the length of the arrow is vector’s magnitude. However the standard plot function is not suitable for this purpose. Fortunately, MATLAB has quiver function appropriately named to plot arrows. quiver(x,y,u,v) plots vectors as arrows at the coordinates (x,y) with components (u,v). The matrices x, y, u, and v must all be the same size and contain corresponding position and velocity components.

Calculate the magnitude of forces OA, OB and the resultant R of OA and OB shown below. Plot all three forces on x-y Cartesian coordinate system Applied Engineering Mechanics by A. Jensen, H. Chenoweth McGraw-Hill Ryerson Limited © 1972, (p. 15) .

Resultant1
Quiver Plot.

% Preparation clear % removes all variables from the current workspace,% releasing them from system memory. clc % clears all input and output from the Command Window display,% giving you a "clean screen." % Input and ComputationOA=[600 320]; % Force 1magOA=sqrt(sum(OA.^2)); OB=[-200 -480]; % Force 2 magOB=sqrt(sum(OB.^2));OC=OA+OB; % The resultant of OA and OB magOC=sqrt(sum(OC.^2)); % The magnitude of resultant force OCangleMag=atan(OC(2)/OC(1))*180/pi; % angle of OC in degrees % Outputdisp(' ') % Display blank line str1= ['The magnitude of the resultant force is ', num2str(magOC), ' N.']; disp(str1);str2= ['The angle of the resultant force is ', num2str(angleMag), ' degrees.'];disp(str2); % Plot Preparationstarts = zeros(3,2); % Origin for all 3 forces, 3x2 "zero" matrix ends = [OA;OB;OC]; % End point for all 3 forces vectors = horzcat(starts,ends); % Concatenate arrays horizontally% Plot Forces on x-y Cartesian Coordinate System % The following MATLAB function plots vectors as arrows% at the coordinates specified in each corresponding % pair of elements in x and y.quiver( vectors( :,1 ), vectors( :,2 ), vectors( :,3 ), vectors( :,4 )); axis equalgrid title('Forces on x-y Cartesian Coordinate System')xlabel('x') % x-axis label ylabel('y') % y-axis labelview(2) % setting view to 2-D

Resultant1_Plot
Output of quiver function.

Write an interactive script to calculate the resultant R of forces F1, F2 and F3 shown below and plot all four forces on x-y Cartesian coordinate system Applied Engineering Mechanics by A. Jensen, H. Chenoweth McGraw-Hill Ryerson Limited © 1972, (p. 15) .

resultant of  3 forces
An example for quiver3 plot.

clear clcdisp('This script computes the resultant of three forces on x-y Cartesian coordinate system.') f1=input('Enter the magnitude of first force in N: ');theta1=input('Enter the angle of first force in deg: '); f2=input('Enter the magnitude of second force in N: ');theta2=input('Enter the angle of second force in deg: '); f3=input('Enter the magnitude of third force in N: ');theta3=input('Enter the angle of third force in deg: '); x1=f1*cos(theta1*pi/180); % The components of forcey1=f1*sin(theta1*pi/180); % The components of force F1=[x1 y1]; % Force 1 x2=f2*cos(theta2*pi/180); % The components of forcey2=f2*sin(theta2*pi/180); % The components of force F2=[x2 y2]; % Force 2 x3=f3*cos(theta3*pi/180); % The components of forcey3=f3*sin(theta3*pi/180); % The components of force F3=[x3 y3]; % Force 3 R=F1+F2+F3; % The resultant of F1, F2 and F3magR=sqrt(sum(R.^2)); % The magnitude of resultant force R angle=atan(R(2)/R(1))*180/pi; % Angle of R in degreesdisp(' ') % Display blank line str1= ['The magnitude of the resultant force is ', num2str(magR), ' N.']; disp(str1);str2= ['The angle of the resultant force is ', num2str(angle), ' degrees.']; disp(str2);starts = zeros(4,3); ends = [F1;F2;F3;R]; ends(3,3)=0; % inputs 0s for z components, making it 3Dvectors = horzcat(starts,ends); % Concatenate arrays horizontally quiver3( vectors( :,1 ), vectors( :,2 ), vectors( :,3 ), vectors( :,4 ), vectors( :,5 ), vectors( :,6 )); % A three-dimensional quiver plot displays vectors with components (u,v,w) at the points (x,y,z), where u, v, w, x, y, and z all have real (non-complex) values.axis equal title('Forces on x-y Cartesian coordinate system')xlabel('x') % x-axis label ylabel('y') % y-axis labelview(2)

quiver3 Example
Output of quiver3 function.

Summary of key points

  1. plot(x, y) and plot3(X1,Y1,Y2) statements create 2- and 3-D graphs respectively,
  2. Plots at minimum should contain the following elements: title , xlabel , ylabel and legend ,
  3. Annotated plots can be easily generated with GUI Plot Tools,
  4. quiver and quiver3 plots are useful for making vector diagrams.

Questions & Answers

A golfer on a fairway is 70 m away from the green, which sits below the level of the fairway by 20 m. If the golfer hits the ball at an angle of 40° with an initial speed of 20 m/s, how close to the green does she come?
Aislinn Reply
cm
tijani
what is titration
John Reply
what is physics
Siyaka Reply
A mouse of mass 200 g falls 100 m down a vertical mine shaft and lands at the bottom with a speed of 8.0 m/s. During its fall, how much work is done on the mouse by air resistance
Jude Reply
Can you compute that for me. Ty
Jude
what is the dimension formula of energy?
David Reply
what is viscosity?
David
what is inorganic
emma Reply
what is chemistry
Youesf Reply
what is inorganic
emma
Chemistry is a branch of science that deals with the study of matter,it composition,it structure and the changes it undergoes
Adjei
please, I'm a physics student and I need help in physics
Adjanou
chemistry could also be understood like the sexual attraction/repulsion of the male and female elements. the reaction varies depending on the energy differences of each given gender. + masculine -female.
Pedro
A ball is thrown straight up.it passes a 2.0m high window 7.50 m off the ground on it path up and takes 1.30 s to go past the window.what was the ball initial velocity
Krampah Reply
2. A sled plus passenger with total mass 50 kg is pulled 20 m across the snow (0.20) at constant velocity by a force directed 25° above the horizontal. Calculate (a) the work of the applied force, (b) the work of friction, and (c) the total work.
Sahid Reply
you have been hired as an espert witness in a court case involving an automobile accident. the accident involved car A of mass 1500kg which crashed into stationary car B of mass 1100kg. the driver of car A applied his brakes 15 m before he skidded and crashed into car B. after the collision, car A s
Samuel Reply
can someone explain to me, an ignorant high school student, why the trend of the graph doesn't follow the fact that the higher frequency a sound wave is, the more power it is, hence, making me think the phons output would follow this general trend?
Joseph Reply
Nevermind i just realied that the graph is the phons output for a person with normal hearing and not just the phons output of the sound waves power, I should read the entire thing next time
Joseph
Follow up question, does anyone know where I can find a graph that accuretly depicts the actual relative "power" output of sound over its frequency instead of just humans hearing
Joseph
"Generation of electrical energy from sound energy | IEEE Conference Publication | IEEE Xplore" ***ieeexplore.ieee.org/document/7150687?reload=true
Ryan
what's motion
Maurice Reply
what are the types of wave
Maurice
answer
Magreth
progressive wave
Magreth
hello friend how are you
Muhammad Reply
fine, how about you?
Mohammed
hi
Mujahid
A string is 3.00 m long with a mass of 5.00 g. The string is held taut with a tension of 500.00 N applied to the string. A pulse is sent down the string. How long does it take the pulse to travel the 3.00 m of the string?
yasuo Reply
Who can show me the full solution in this problem?
Reofrir Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, A brief introduction to engineering computation with matlab. OpenStax CNX. Nov 17, 2015 Download for free at http://legacy.cnx.org/content/col11371/1.11
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'A brief introduction to engineering computation with matlab' conversation and receive update notifications?

Ask