Software_Simulation_paper_chapter3u
Software_Simulation_paper_chapter3u
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
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:
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:
The xlabel and ylabel commands generate labels along x-axis and y-axis.
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.
Example
x = [0:0.01:10];
y = sin(x);
4
Drawing Multiple Functions on the Same Graph
Example
x = [0 : 0.01: 10];
y = sin(x);
g = cos(x);
plot(x, y, x, g, '.-'),
legend('Sin(x)', 'Cos(x)')
Example
g = 5 * x.^3 + 9 * x + 2;
When you run the file, MATLAB generates the following graph:
5
Setting Axis Scales
x = [0 : 0.01: 10];
we need to keep the plotted graph in its window. For this we use the hold on command as follows:
>> hold on
>> 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,'--')
>> xlabel('x-axis')
>> legend('sinx','cosx')
6
Generating SubPlots
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 ,
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.
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
7
Three-Dimensional Plots
Example
x = [0:0.01:5];
y = exp(-1.5*x).*sin(10*x);
subplot(1,2,1)
y = exp(-2*x).*sin(10*x);
subplot(1,2,2)
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.
Example
[x,y] = meshgrid(-2:0.2:2);
g = x .* exp(-x.^2 - y.^2);
surf(x, y, g)
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
10