Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Modeling and Simulation Lecture Notes: Introduction to Matlab and 2D Plotting, Slides of Mathematical Modeling and Simulation

Lecture slides on modeling and simulation, focusing on the introduction to matlab and creating 2d plots. It covers creating vectors, plotting functions, and customizing plots with labels, text, and grids. It also introduces various plotting commands and multiple graphs.

Typology: Slides

2011/2012

Uploaded on 07/03/2012

jaee
jaee 🇮🇳

4.7

(22)

101 documents

1 / 38

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture Slides
on
Modeling and Simulation
Lecture: Introduction to Matlab
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26

Partial preview of the text

Download Modeling and Simulation Lecture Notes: Introduction to Matlab and 2D Plotting and more Slides Mathematical Modeling and Simulation in PDF only on Docsity!

Lecture Slides

on

Modeling and Simulation

Lecture: Introduction to Matlab

Creating a 2D Plot

x = 0:pi/100:2pi; y = sin(x); plot(x,y,'LineWidth',3)*

Now label the axes and add a title. The characters \pi create the symbol. See text strings for more symbols: xlabel('x = 0:2\pi') ylabel('Sine of x') title('Plot of the Sine Function','FontSize',12)

For example, these statements use the colon operator to create a vector of x values ranging from 0 to 2, compute the sine of these values, and plot the result:

Graph is on

next page

Plotting Elementary Functions

% prog2.m t = -1 : 0.01 : 1; f = 4.5cos(2pit - pi/6); plot(t,f 'LineWidth',3),title('Fig.2a'); axis([-1, 1, -6, 6]); xlabel('time, t'); ylabel('f(t)'); text(-0.6, 5,' f(t) = A cos(wt + phi)'); grid;*

Example of a graph ploting with labels and text and grid.

Graph is on

next page

Plotting Elementary Functions

Resulting graph

Specifying the Color and Size of Markers

Resulting

figure

Plotting commands

PLOT(X,Y) plots vector Y versus vector X. TITLE('text') adds text at the top of the current plot. XLABEL('text') adds text beside the X-axis on the current axis. YLABEL('text') adds text beside the Y-axis on the current axis. GRID, by itself, toggles the major grid lines of the current axes.

GTEXT('string') displays the graph window, puts up a cross-hair, and waits for a mouse button or keyboard key to be pressed. SUBPLOT(m,n,p), or SUBPLOT(mnp),

breaks the Figure window into an m-by-n matrix of small axes. STEM(Y) stemDiscrete sequence or "stem" plot. STEM(Y) plots the data sequence Y as stems from the x axis terminated with circles for the data value. SEMILOGX(...) is the same as PLOT(...), except a logarithmic (base 10) scale is used for the X-axis. SEMILOGY(...) is the same as PLOT(...), except a logarithmic (base 10) scale is used for the Y-axis..

Results

Multiple Graphs

Plotting colors and line styles

Colors Line Styles y yellow. point M magenta o circle C cyan x x-mark R red + plus G green - solid B blue * star W white : dotted K black -. Dashdot -- dashed More mark types are; square(s), diamond(d), up-triangle(v), down- triangle(^), left-triangle(<), right-triangle(>), pentagram(p), hexagram(h) See also help plot for more line and mark color.

Results

subplots

Various Plotting Functions:

 2 dimensions line plots (x vs. y),  filled plots,  bar charts,  pie charts,  parametric plots,  polar plots,  contour plots,  density plots,  log axis plots,  surface plots,  parametric plots in 3 dimensions  and spherical plots.

To preview some of these capabilities and others as well, enter the command demos.

MATLAB supports many types of graph and surface plots:

Line Plots of 3-D Data

Production of helix

3-D Plots

MATLAB Commands for Mesh and Surface

meshgrid: generate X and Y arrays for 3-D plots mesh: draws a wireframe mesh surf: plot a 3-D shaded surface colorbar: add a color bar tool patch: creating patch graphics objects hidden: remove hidden lines from mesh plot

Mesh and Surface (Example) (2)

0

10

0

10

-0.

0

Z = sin(R)./R; mesh(X,Y,Z) 1

Three-D meshgrid

Mesh and Surface

Three-D meshgrid