Software Simulation Paper Chapter2u
Software Simulation Paper Chapter2u
Software Simulation
Dr.Fatma Khammar
November 2023
5.0
Table of contents
Introduction 3
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
Data types and variables
The command
>> v'
Then give the transpose of this vector, that is to say here a column vector. We can also write
>> z = v'
Or
>> v(2)
Which simply gives access to the second element, i.e. here 22. It is also possible to use the “:” to select several
elements of a vector
>> v(1:3)
>> v (1:2:5)
4
Matrices in Matlab
Which gives access to elements that go from 1 to 5, but incrementing with a step of 2. In this case, the vector
(11 33 55) is returned.
>> v
>> v (:)
The symbol “:” without further details meaning “the whole vector”. Matlab allows the multiplication of vectors,
however we will monitor the order of what we write: so if vec*vec, returns an error message, vec*vec' returns a
matrix and vec'*vec a number.
2. Matrices in Matlab
We have just seen our first matrix. In fact, it is enough to add a dimension to the vectors to create matrices with
the same notations. Thus
It is important to pay attention to the size of the objects that you define otherwise you will get error messages.
If we want to create a matrix from its columns, simply write
To read the elements, we use the same method as before. So the order.
>> A(1,3)
Allows access to the element (1,3) of the matrix A, which here is 3. Likewise
>> A(1:3,2:3)
Another way to construct vectors in MATLAB is to use the linspace command (using parentheses) , the vector
V contains p numbers between n and m as follows:
>> b = linspace(0,5,10)
b=
Columns 1 through 10
length(y)
The length of a vector is the number of elements contained in the vector. In order to obtain the length of a
vector, we use the MATLAB command length as follows:
>> length(b)
ans =
10
5
Matrices in Matlab
sum(y)
In order to add the total sum of the values of the elements of a vector, we use the MATLAB command sum as
follows:
>> y = [ 1 3 0 5 -2 ]
y=
1 3 0 5 -2
>> sum(y)
ans =
In order to find the minimum value and the maximum value of the elements of a vector, we use the MATLAB
commands min and max, respectively, as follows:
>> y = [ 1 3 0 5 -2 ]
>> min(y)
ans =
-2
>> max(y)
Elements of a vector can be sorted using the MATLAB command sort as follows:
>> x = [2 1 -3 5 3]
x=
2 1 -3 5 3
>> sort(x)
ans =
-3 1 2 3 5
There are some MATLAB commands for statistics that can be used with vectors. For example, the MATLAB
commands mean, and median can be used to obtain the statistical values of range, mean, and median for a set of
numbers in a vector as follows:
[ y , I ] = find (x) : retuns rows ( in vector I ) and columns ( in vector J ) non zero elements
of x,
6
Deleting row or column
median(x) : median
A(i1:i2,:) : lines i1 to i2 of A
A(:,j1:j2) : columns j1 to j2 of A
>> A(:,2)=[]
ans =
13
46
>> A(3,:) = []
A=
123
456
Third row of matrix A is now deleted. To restore the third row, we use a technique for
creating a matrix
A=
123
456
789
To determine the dimensions of a matrix or vector, use the command size. For example,
>> size(A)
ans =
7
Simplification of algebraic expression
33
>> [m,n]=size(A)
- double
>>double (s)
ans = 13.9282
- Example
P=n(n+1)(n+2)(n+3)+1
For this we build, using the sym command, asymbolic expression P in which the letter n appears.
8
simplify , factor , collect , expand
Then we use the subs command to replace n by 2 in the expression P. Finally the factor command allows you to
factor the result and put in evidence a perfect square.
To show that P is always the square of on integer, we directly factor the expression P:
The result always shows that P is always the square of the integer
- Using syms
A simple variable ( mathematics) such that, n , x , θ , is itself an elementary symbolic expression and it is often
convenient to assign it to a variable (computer) of the same name:
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