0% found this document useful (0 votes)
5 views

Software_Simulation_paper_chapter3u

Uploaded by

perlaperdido3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Software_Simulation_paper_chapter3u

Uploaded by

perlaperdido3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Software Simulation

Software Simulation

Dr.Fatma Khammar

November 2023
5.0
Table of contents
Introduction 3

I - GRAPHICS 4

1. Introduction .................................................................................................................................................... 4

2. Adding Title, Labels, Grid Lines, and Scaling on the Graph .......................................................................... 4

3. Drawing Multiple Functions on the Same Graph ............................................................................................ 5

4. Setting Colors on Graph .................................................................................................................................. 5

5. Setting Axis Scales .......................................................................................................................................... 6

6. Generating SubPlots ........................................................................................................................................ 7

7. Three-Dimensional Plots ................................................................................................................................ 8

References 10
Introduction

Simulation software is used to simulate the dynamic behavior of a system that is represented by a mathematical
model. At each stage of the model simulation, the state of each part of the system is calculated using time-based or
event-based solvers. Typically, simulation software also includes visualization tools, such as data displays, that allow
the simulation to be monitored as it runs. Engineers and scientists use simulation software for many reasons:

- It is often less expensive and simpler to create and simulate a model than to create and test a hardware
prototype.

- If the hardware prototype is not available early enough in the development process, you can use simulation
software to explore the design space and test different scenarios as early as possible.

- Once the hardware prototype is available, you can connect it to simulation software to verify that the software
and hardware elements of the system communicate correctly.

Simulation is a virtual mathematical process involving a computer that processes input data representing very
specific “real-world” conditions. Ideally, you detail the constraints and loads to which the product will be subjected
and then, based on the results of the simulation, you correct the design defects or anticipate them. But simulation is
not just a tool for perfecting the design you have decided on. Simulation allows you to optimize your design, and is
different from the iteration process where you test each iteration. You can carry out feasibility and optimization
studies to achieve the objectives.

3
GRAPHICS

GRAPHICS
I
1. Introduction
This lesson show exploring the plotting and graphics capabilities of MATLAB. To plot the graph of a function,
you need to take the following steps:

Define the function, y = f(x)

Call the plot command, as plot(x, y)

Following example would demonstrate the concept. Let us plot the simple function y = x for the range of values
for x from 0 to 100, with an increment of 5.

x = [0:5:100];

y = x;

plot(x, y)

When you run the file, MATLAB displays the following plot:

2. Adding Title, Labels, Grid Lines, and Scaling on the Graph


MATLAB allows you to add title, labels along the x-axis and y-axis, grid lines and also to adjust the axes to
spruce up the graph.

The xlabel and ylabel commands generate labels along x-axis and y-axis.

The title command allows you to put a title on the graph.

The grid on command allows you to put the grid lines on the graph.

The axis equal command allows generating the plot with the same scale factors and the spaces on both axes.

The axis square command generates a square plot.

Example

x = [0:0.01:10];

y = sin(x);

plot(x, y), xlabel('x'), ylabel('Sin(x)'), title('Sin(x) Graph'),

grid on, axis equal

4
Drawing Multiple Functions on the Same Graph

MATLAB generates the following graph:

3. Drawing Multiple Functions on the Same Graph


You can draw multiple graphs on the same plot. The following example demonstrates the concept:

Example

x = [0 : 0.01: 10];

y = sin(x);

g = cos(x);

plot(x, y, x, g, '.-'),

legend('Sin(x)', 'Cos(x)')

MATLAB generates the following graph:

4. Setting Colors on Graph


MATLAB provides eight basic color options for drawing graphs. The following table shows the colors and their
codes:

Example

Let us draw the graph of two polynomials

x = [-10 : 0.01: 10];

y = 3*x.^4 + 2 * x.^3 + 7 * x.^2 + 2 * x + 9;

g = 5 * x.^3 + 9 * x + 2;

plot(x, y, 'r', x, g, 'g')

When you run the file, MATLAB generates the following graph:

5
Setting Axis Scales

5. Setting Axis Scales


The axis command allows you to set the axis scales. You can provide minimum and maximum values for x and
y axes using the axis command in the following way:

axis ( [xmin xmax ymin ymax] )

The following example shows this:

x = [0 : 0.01: 10];

y = exp(-x).* sin(2*x + 3);

plot(x, y), axis([0 10 -1 1])

MATLAB generates the following graph:

we need to keep the plotted graph in its window. For this we use the hold on command as follows:

>> hold on

>> title('This is an example of a simple graph')

>> xlabel('x')

>> ylabel('y')

Also, note the use of the MATLAB command legend to get a legend displayed at the top right corner of the
graph.

>> x = 0:pi/20:2*pi;

>> y = sin(x);

>> z = cos(x);

>> plot(x,y,'-',x,z,'--')

>> hold on;

>> grid on;

>> title('Sine and Cosine Functions')

>> xlabel('x-axis')

>> ylabel('sine and cosine')

>> legend('sinx','cosx')

6
Generating SubPlots

Figure : Example of two curves on the same graph

hold on : the next plots will be superimposed on the plots already made,

hold off : the content of the active graphics window will be erased at the next plot ,

clf : clears the contents of the active graphics window

close : closes the active graphics window

close all : closes all graphics window

gtext(‘ texte') : text positioned using the mouse,

6. Generating SubPlots
When you create an array of plots in the same figure, each of these plots is called a subplot. The subplot
command is used for creating subplots.

Syntax for the command is:

subplot(m, n, p)

where, m and n are the number of rows and columns of the plot array and p specifies where to put a particular
plot.

Each plot created with the subplot command can have its own characteristics.

You can draw multiple graphs in the same window using the instruction subplot for divide the window into
multiple parts

Divide the window into twoparts (2x1)

Divide the window into twoparts (1x2)

Divide the window into four parts (2x2)

Divide the window into four parts (4x1)

7
Three-Dimensional Plots

Following example demonstrates the concept:

Example

Let us generate two plots:

Create a script file and type the following code:

x = [0:0.01:5];

y = exp(-1.5*x).*sin(10*x);

subplot(1,2,1)

plot(x,y), xlabel('x'), ylabel('exp(–1.5x)*sin(10x)'), axis([0 5 -1 1])

y = exp(-2*x).*sin(10*x);

subplot(1,2,2)

plot(x,y), xlabel('x'), ylabel('exp(–2x)*sin(10x)'), axis([0 5 -1 1])

When you run the file, MATLAB generates the following graph:

7. Three-Dimensional Plots
Three-dimensional plots basically display a surface defined by a function in two variables, g = f (x,y).

As before, to define g, we first create a set of (x,y) points over the domain of the function using the meshgrid
command. Next, we assign the function itself. Finally, we use the surf command to create a surface plot.

The following example demonstrates the concept:

Example

Let us create a 3D surface map for the function

[x,y] = meshgrid(-2:0.2:2);

g = x .* exp(-x.^2 - y.^2);

surf(x, y, g)

MATLAB displays the following 3-D map:

8
Three-Dimensional Plots

You can also use the mesh command to generate a three-dimensional surface. However, the surf command
displays both the connecting lines and the faces of the surface in color, whereas, the mesh command creates a
wireframe surface with colored lines connecting the defining points.

9
References

References
Introduction to MATLAB for Engineers
1 William J. Palm III “University of Rhode Island “

MATLAB
2 The Language of Technical Computing

INTRODUCTION TO MATLAB FOR ENGINEERING STUDENTS


David Houcque
Northwestern University
3 (version 1.2, August 2005)

10

You might also like