digital simulation lab-1
TRANSCRIPT
-
7/25/2019 Digital Simulation Lab-1
1/73
Allabakshu ShaikDigital Simulation Lab-1
1
Nimra Institute of Science and Technology
NIMRA INSTITUTE OF SCIENCE AND TECHNOLOGYJUPUDI(V), IBRAHIMPATNAM(M), KRISHNA(D).
DEPARTMENT OF AERONAUTICAL ENGINEERING
DIGITAL SIMULATIN LAB-I
BY
ALLABAKSHU SHAIK
Head Of The Department
Aeronautical Engineering
-
7/25/2019 Digital Simulation Lab-1
2/73
Allabakshu ShaikDigital Simulation Lab-1
2
Nimra Institute of Science and Technology
CONTENTS
1.
Introduction to CFD 32. Introduction to FLUENT and GAMBIT 9
3. SIMULATION OF FLOW PAST OVER A 2D AIRFOIL 10
4. SIMULATION OF FLOW OVER 3D WING 18
5. SIMULATION OF COMPRESSIBLE FLOW IN A CONVERGENT-
DIVERGENT NOZZLE 26
6. INTRODUCTION TO MAT LAB 34
7.
-
7/25/2019 Digital Simulation Lab-1
3/73
Allabakshu ShaikDigital Simulation Lab-1
3
Nimra Institute of Science and Technology
1. INTRODUCTION TO CFD
Computational fluid dynamics (CFD) is a new third approach in the philosophical study anddevelopment of the whole discipline of fluid dynamics rather than theoretical and experimentalapproaches. CFD is today an equal partner with pure theory and pure experiment in the analysis
of and solution of fluid flow problems. So we can say CFD is one of the branches of fluid
mechanics that uses numerical methods and algorithms to solve and analyze problems thatinvolve fluid flows. Computers are used to perform the millions of calculations required to
simulate the interaction of liquids and gases with surfaces defined by boundary conditions. Even
with high-speed supercomputers only approximate solutions can be achieved in many cases.
Ongoing research, however, may yield software that improves the accuracy and speed ofcomplex simulation scenarios such as transonic or turbulent flows. Initial validation of such
software is often performed using awind tunnel with the final validation coming inflight test.
CFD is a Research design tool whose results are directly analogous to wind tunnel results
obtained in a laboratory-they both represent set of data for given flow configurations at different
Mach numbers, Reynolds numbers, etc.
Working Architecture:
The following steps describe the working architecture of CFD:
1. Mathematical model: The first step is to select the mathematical model which defines
the physics of fluid flow model which is to be simulated. For example we have to solve
fluid flow over a body to find lift, drag, vortex shedding, etc. We have to translate thisproblem into mathematical model, formed generally by a set of partial differential
equations (Governing equations like Navier and stokes equation) and additional lawsdefining the type of fluid, the eventual dependence of key parameters, such as viscosity
and heat conductivity in function of other flow quantities, such as temperature, velocity,
pressure etc.
2. Discretization:Once the mathematical model is selected, the second step which is the
major process of simulation, namely discretization process. The most fundamental
consideration in CFD is how one treats a continuous fluid in a discretized fashion on a
computer. Discretization is the process by which a closed form mathematical expression,
such as a function or a differential or integral equation involving functions, all of whichare viewed as having an infinite continuum of values throughout some domain, is
approximated by analogous (but different) expressions which prescribe values at only afinite number of discrete points or volumes in the domain known as grid points.
http://en.wikipedia.org/wiki/Fluid_mechanicshttp://en.wikipedia.org/wiki/Fluid_mechanicshttp://en.wikipedia.org/wiki/Numerical_methodshttp://en.wikipedia.org/wiki/Algorithmshttp://en.wikipedia.org/wiki/Supercomputerhttp://en.wikipedia.org/wiki/Turbulencehttp://en.wikipedia.org/wiki/Wind_tunnelhttp://en.wikipedia.org/wiki/Flight_testhttp://en.wikipedia.org/wiki/Flight_testhttp://en.wikipedia.org/wiki/Wind_tunnelhttp://en.wikipedia.org/wiki/Turbulencehttp://en.wikipedia.org/wiki/Supercomputerhttp://en.wikipedia.org/wiki/Algorithmshttp://en.wikipedia.org/wiki/Numerical_methodshttp://en.wikipedia.org/wiki/Fluid_mechanicshttp://en.wikipedia.org/wiki/Fluid_mechanics -
7/25/2019 Digital Simulation Lab-1
4/73
Allabakshu ShaikDigital Simulation Lab-1
4
Nimra Institute of Science and Technology
Analyzing phase: After the discretization step, a set of algebraic relations betweenneighboring mesh point values is obtained, one relation for each mesh point. This set of
equations, defining the numerical scheme, has now to be analyzed for its properties; we
have to investigate the consistency, stability and convergence which give the validity andaccuracy of a numerical scheme with the assurance that the results of the computer
simulation indeed represent a valid approximation of our reality.
3. Resolution phase: In this step solve the numerical scheme to obtain the mesh pointvalues of the main flow variables. The solution algorithms depend on the type of problem
we are simulating, i.e. time dependent or steady flows. This will require techniques either
to solve a set of ordinary differential equations in time, or to solve an algebraic system.
4. Analyzing Results: This is the last step in which graphic post processing is obtained for
the numerical data to understand and interpret the physical properties of the obtained
simulated results.Briefly we can describe these five steps in three steps according to our software usages.
They are:
1. Preprocessing:
Generate the geometry of Physical flow problem like flow over a body,flow in a nozzle with boundaries in GAMBIT.
Mesh the flow field using different techniques in GAMBIT to get the gridpoints in the flow domain of the model.
Export the meshed model into FLUENT where we can solve the problem.
Set the initial conditions of the flow like steady or unsteady, implicit orexplicit, materials etc.
Select the type of model inviscid, laminar, turbulent, with heat convectionetc.
Give the input values of the flow field like velocity, pressure, temperature,density etc.
The work of the Mathematical model, Discretization has been done in this one
step.
2. Processing:
Run the numerical scheme we had chosen.
Increase the number of iterations to get the consistency, stability andconvergence of the problem.The work of analyzing and resolution phase has been done in this step.
-
7/25/2019 Digital Simulation Lab-1
5/73
Allabakshu ShaikDigital Simulation Lab-1
5
Nimra Institute of Science and Technology
3.
Post processing: Collect and organize the data.
Analyze the results by plotting graphs with collected data.
Visualize the CFD results by plotting contours of pressure, velocityvectors, Path lines, streak lines.
The work of analyzing results has been done in this step.
Potential Benefits:
More cost effective and more rapid solutions than experimental fluid dynamics. Full scale simulations (e.g. ships, airplanes, missiles etc) can be done.
Environmental effects like wind, weather can be avoided. Hazardous like explosions, pollution, radiation can be avoided. CFD provides high-fidelity database for diagnosing flow field. Its applications are in various fields like Aerospace, automobile, chemical processing,
hydraulics, oil and gas, marine, biomedical, sports, power generation etc.
Therefore CFD is a computer program, which is a readily transportable wind tunnel.
Spatial Discretization:
Spatial discretization consists in setting up a mesh or a grid, by which the continuum of
space is replaced by a finite number of points where the numerical values of the variableswill have to be determined. It is intuitively obvious that the accuracy of a numerical
approximation will be directly dependent on the size of the mesh that is the closer the
points the better the discrertized space approaches the continuum, the better theapproximation of the numerical scheme. In other words, the error of a numerical
simulation has to tend to zero when the mesh size tends to zero, and the pace of this
variation will be characterized by the order of the numerical discretization.
PDE Discretization:
The generation of an appropriate grid or mesh is one thing; the solution of the governing
flow equation over such a grid is quite another thing. Once a mesh or grid has beendefined, the equations can be discretized leading to the transformation of the differentialor integral equations to discrete algebraic operations involving the values of the
unknowns related to the mesh points. The basis of all numerical methods consists in this
transformation of the mathematical model into an algebraic, linear or nonlinear, system ofequations for the mesh related unknown quantities.
-
7/25/2019 Digital Simulation Lab-1
6/73
Allabakshu ShaikDigital Simulation Lab-1
6
Nimra Institute of Science and Technology
Grid Generation:
After defining governing equations for the given flow field problem then it is the time to
solve the whole system of governing equations for the flow field variables. To carry outthis work first of all, the space, where the flow is to be computed the physical space, is
to be divide in to a large number of geometrical elements called grid cells. This process is
termed grid generation (mesh). It can also be viewed as placing first grid points (alsocalled nodes or vertices) in the physical space and then connecting them by straight lines-
grid lines. The grid normally consists in two dimensions of triangles or quadrilaterals,
and in three dimensions of tetrahedral, hexahedra, prisms, or pyramids.
The most important requirements placed on a grid generation tool are that there must not
be any holes between the grid cells but also that the grid cells do not overlap.
Additionally, the grid should be smooth, i.e., there should be no abrupt changes in the
volume of the grid cells or in the stretching ratio and the elements should be as regular aspossible. Furthermore, if the grid consists of quadrilaterals or hexahedra, there should be
no large kinks in the grid lines. Otherwise, numerical errors would increase significantly.
There exist basically two types of grids:
Structured grids (Fig. 1.1) - each grid point (vertex, node) is uniquely identified by the indices
i, j, k and the corresponding Cartesian coordinates xi,j,k, y i,j,k,, and z i,j,k,. The grid cells are
quadrilaterals in 2D and hexahedra in 3D. If the grid is body-fitted, we also speak of curvilineargrid.
Fig 1.1 Structured grid in computational space.
-
7/25/2019 Digital Simulation Lab-1
7/73
Allabakshu ShaikDigital Simulation Lab-1
7
Nimra Institute of Science and Technology
Unstructured grids (Fig. 1.2) - grid cells as well as grid points have no particular ordering, i.e.,
neighboring cells or grid points cannot be directly identified by their indices (e.g., cell 6 adjacent
to cell 119). In the past, the grid cells were triangles in 2D and tetrahedra in 3D. Today,unstructured grids usually consist of a mix of quadrilaterals and triangles in 2D and of
hexahedra, tetrahedra, prisms and pyramids in 3D, in order to resolve the boundary layers
properly. Therefore, we speak in this case of hybrid or mixed grids.
Fig 1.2 Unstructured, mixed grid approach; numbers mark individual cells.
The main advantage of structured grids follows from the property that the indices i, j, k represent
a linear address space - also called the computational space, since it directly corresponds to how
the flow variables are stored in the computer memory. This property allows it to access theneighbor of a grid point, very quickly and easily, just by adding or subtracting an integer value to
or from the corresponding index (e.g., like (i+l), (j-1), etc. - see Fig. 1.1. As one can imagine, the
evaluation of gradients, fluxes, and also the treatment of boundary conditions is greatlysimplified by this feature.
The second types of grids are the unstructured grids. They offer the largest flexibility in the
treatment of complex geometries. The main advantage of the unstructured grids is based on the
fact that triangular (2D) or tetrahedral (3D) grids can in principle be generated automatically,independent of the complexity of the domain. In practice, it is of course still necessary to set
some parameters appropriately, in order to obtain a good quality grid. Furthermore, in order toresolve the boundary layers accurately] it is advisable to employ in 2D rectangular and in 3D
prismatic or hexahedral elements near solid walls. Another benefit of such mixed grids is the
reduction of the number of grid cells, edges, faces and possibly also of grid points. But, oneshould keep in mind that the generation of mixed grids is non-trivial for geometrically
demanding cases. However, the time required to construct an unstructured, mixed grid for a
-
7/25/2019 Digital Simulation Lab-1
8/73
Allabakshu ShaikDigital Simulation Lab-1
8
Nimra Institute of Science and Technology
complex configuration is still significantly lower than the one required for a multiblockstructured grid. Since nowadays, the geometrical fidelity of the flow simulations is rapidly
increasing; the ability to generate grids fast and with minimum user interaction becomes more
and more important. This is particularly true in industrial environment. Another advantage of theUnstructured grids are that solution dependent grid refinement and coarsening can be handled in
relatively native and seamless manner. To mention also the disadvantages of unstructured
methods, one of them is the necessity to employ sophisticated data structures inside the flow
solver. Such data structures work with indirect addressing which, depending on the computerhardware leads to more or less reduced computational efficiency. Also the memory requirements
are in general higher as compared to the structured schemes. But despite all problems, the
capability to handle complex flow problems in short turn-around times still weights much more.
From this point, it is not surprising that for example nearly all vendors of commercial CFDsoftware switched over to unstructured flow solvers.
Introduction to Aerodynamics:
The study of the dynamics of air is known as aerodynamics. It includes theintermolecular forces, the motion of molecules due to variation of flow field variables
like pressure, velocity, temperature etc.
Aerodynamics is an applied science with many practical applications in engineering. No
matter how elegant an aerodynamic theory may be, or how mathematically complex a
numerical solution may be, or how sophisticated an aerodynamic experiment may be, allsuch efforts are usually aimed at one or more of the following practical objectives:
1.
The prediction of forces and moments on, and heat transfer to, bodies movingthrough air. For example:
Estimation of lift, drag and moments of airfoils, wings, fuselages, engine
nacelles and whole airplane.
Aerodynamic heating of flight vehicles ranging from the supersonictransport to planetary probe entering the atmosphere of Jupiter.
2. Determination of flows moving internally through ducts. For example:
To calculate and measure the flow properties in compressors, combustionchamber, nozzle of rockets and air breathing jet engines and to calculateengine thrust.
To know the flow conditions in the test section of a wind tunnel.
To know how much fluid can flow through pipes under differentconditions.
A very interesting application of aerodynamics is high-energy chemicaland gas dynamic lasers.
The applications of step 1 come under external aerodynamics whereas
step 2 comes under internal aerodynamics.
-
7/25/2019 Digital Simulation Lab-1
9/73
Allabakshu ShaikDigital Simulation Lab-1
9
Nimra Institute of Science and Technology
2.
Introduction to FLUENT and GAMBIT
GAMBITis the program used to generate the grid or mesh for the CFD solver.The GAMBIT software package is designed to help analysts and designers buildand mesh models for computational fluid dynamics (CFD) and other scientific
applications. GAMBIT receives user input primarily by means of its graphical
user interface (GUI). The GAMBIT GUI makes the basic steps of building and
meshing a model simple and intuitive, yet it is versatile enough to accommodatea wide range of modeling applications.
FLUENT is a state-of-the-art computer program for modeling fluid flow andheat transfer in complex geometries. FLUENT is written in the C computer
language and makes full use of the exibility and powered by the language. Fluent
is the CFD solver which can handle both structured grids, i.e. rectangular gridswith clearly defined node indices, and unstructured grids. unstructured grids are
generally of triangular nature, but can also be rectangular. In 3-D problems,
unstructured grids can consist of tetrahedral (pyramid shape), rectangular boxes,prisms, etc.
-
7/25/2019 Digital Simulation Lab-1
10/73
Allabakshu ShaikDigital Simulation Lab-1
10
Nimra Institute of Science and Technology
3.
SIMULATION OF FLOW PAST OVER A 2D AIRFOIL
Aim:To draw the graphs Cl- and Cd- for the flow past over a 2D NACA 0012 airfoil withthe following flow conditions:
Mach number =0.3
= 50, 8
0, 12
0.
Software: GAMBIT and FLUENT.
Procedure:The following steps give the procedure to simulate the flow over airfoil.
1.
Create geometry in Gambit:
To create geometry of the given problem select the geometry command buttonfrom operation tool pad.
Import the vertex data of NACA 0012 airfoil.
Create a two smooth airfoil edge for the upper surface and lower surface vertexdata by selecting Nurbs option from the Edge command of Geometry toolpad.
Split the upper surface into HI, IG, and lower surface HJ, JG by selecting splitedge option from Edge command with X=0.3 as chordlength(c) = 1.01.
Create the farfield boundary for the airfoil by creating vertices and joining themappropriately to form edges using vertex command from geometry toolpad as per
the following table:
Label X-coordinate Y-coordinate Z-coordinate
A 1.01 12.625 0
B 21.21 12.625 0
C 21.21 0 0
D 21.21 -12.625 0
E 1.01 -12.625 0
F -11.615 0 0
G 1.01 0 0
Create the straight edges GA, AB, BC, CD, DE, EG, CG using straight edge
command and circular arc edges EF, FA with center as G using arc edgecommand from geometry tool pad. Thus the farfield boundary is created for the
airfoil.
Create the face ABCGA by selecting GA, AB, BC, CG edges in create face fromwireframe command. Similarly create faces GCDEG, GEFAG, airfoil (HIGJH).
Subtract the airfoil face from GEAFG face using subtract real faces command.
-
7/25/2019 Digital Simulation Lab-1
11/73
Allabakshu ShaikDigital Simulation Lab-1
11
Nimra Institute of Science and Technology
Thus the geometry of flow over 0012 airfoil has been completed.
2. Mesh geometry in Gambit:
To create the mesh for the geometry select mesh command button from theoperation tool pad.
Instead of directly meshing the faces of geometry, first we mesh the edges bygiving inputs like type of mesh, ratio or length of nodes, direction, interval count
or size for each edge of the geometry in Mesh Edges command button as follows:Edges GA and BC
Type : Successive ratio
Ratio : 1.15
Direction : from G to A and C to BInterval count : 45
Edges EG and CDType : Successive ratioRatio : 1.15
Direction : from G to E and C to D
Interval count : 45
Edges AB, CG and DEType : First Length
Length : 0.0202
Direction : from A to B, G to C and E to DInterval count : 60
Edges HI and HJ
Type : Last LengthLength : 0.0202Direction : from H to I and H to J
Interval count : 40
Edges IG and JGType : Successive ratio
Ratio : 1
Direction : from I to G and J to GInterval size : 0.0202
To mesh the edges AF and EF we should find the number of nodes on upper
surface and lower surface of the airfoil which should be equal to the nodesobtained by meshing edges AF and EF respectively.
So select Edge command-summarize edge mesh. Select edge IJ and then elements
under component and click apply then number of divisions will appear. So, the
interval count for edge AF is NHI+NIG= 40+36 = 76. Similarly for the edge EF
also interval count is NHJ+NJG= 40+36 = 76.
-
7/25/2019 Digital Simulation Lab-1
12/73
Allabakshu ShaikDigital Simulation Lab-1
12
Nimra Institute of Science and Technology
Edges AF and EF
Type : First Length
Length : 0.0202Direction : from A to F and E to F
Interval count : 76
Go to Mesh Faces select the face GABCG and make sure that type of mesh ismap, elements are quad and then apply then we will get a meshed face. Similarlyfor face GCDEG and subtracted face of GEFAG with airfoil.
Thus the Meshed geometry for the given flow problem is obtained.
3. Specify boundary types in Gambit:
Create groups of edges and then create boundary entities from these groups.
Go to operation tool pad-geometry command button-group command button-create group.
Select edges AF and EF label it as farfield1.
Similarly edges AB and DE as farfield2, edges BC and CD as farfield3 and edges
HI, IG, HJ, JG as airfoil.
To define boundary types select operation toolpad-zones command button-specifyboundary type.
Under entity select group and give type of boundary as follows: For airfoil boundary type is wall and the rest are pressure fields.
Save file and export mesh file.
-
7/25/2019 Digital Simulation Lab-1
13/73
Allabakshu ShaikDigital Simulation Lab-1
13
Nimra Institute of Science and Technology
4. Set the problem in Fluent:
Start Fluent, select 2ddp and click run.
Import 0012.msh file from Main menu-File-Read-Case.
Data is displayed relating boundary types and zones of the flow field.
To know the number of cells and nodes in grid select Grid-Info-Size then data isdisplayed.
To select numerical scheme define the model properties as followsDefine - model - solver
Solver - segragated
Space - 2DVelocity formulation - Absolute
Formulation - implicit
Timesteady - ok
Define - model - viscous - inviscid-ok
DefinemodelEnergy - turned off.
Define - Materials
Name - airType of material - fluid
Density - constant = 1.225 - change/create.
Define - operating conditionsOperating pressure (pascal) = 101325-ok
Define-Boundary conditionsZone - farfield1 and farfield2 - velocity inlet
velocity specification method - components
Reference frame - AbsoluteX component (m/s) = 101.61
Y component (m/s) = 8.89
Zone - farfield3 - pressure outlet
Gauge pressure (pa) = 0Zone - wall - wall.
Now the flow problem is ready to solve.
-
7/25/2019 Digital Simulation Lab-1
14/73
Allabakshu ShaikDigital Simulation Lab-1
14
Nimra Institute of Science and Technology
5. Solve the problem:
SolveControls - solution
Discretizationpressure - presto and Momentum - second order upwind -ok
SolveIntialize - IntializeCompute from - Farfield1 - Init.
Solve - Monitors-Residual - convergence criteria = 1e-06
SolveMonitors - Forces
Options-print and plot
Coefficient - Lift and Drag-Apply.Wall zones-wall
Force vectorX = -0.0872 and Y = 0.9962 for coefficient of Lift
X = 0.9962 and Y = -0.0872 for coefficient of Drag
Report-Reference valuescompute fromfarfield1ok
Filewritecase
Solveiteratenumber of iterations = 500 to get convergence
For each iteration we get coefficient of lift and coefficient of drag and weconsider the correct values where it converges.
Filewritecase and data
6. Analyze results:
PlotXY plot.
Change the Y-axis function to pressure followed by pressure coefficient.
Select airfoil under surfaces. Click on Plot.
Distribution of pressure coefficient on airfoil is displayed.
DisplayContours.
Select pressure, static pressure under contours and then display.
Similarly obtain velocity contours and etc.
-
7/25/2019 Digital Simulation Lab-1
15/73
Allabakshu ShaikDigital Simulation Lab-1
15
Nimra Institute of Science and Technology
This plot shows pressure coefficient over NACA 0012 airfoil at =50
This plot shows pressure contours over flow field when NACA 0012 airfoil at =50
-
7/25/2019 Digital Simulation Lab-1
16/73
Allabakshu ShaikDigital Simulation Lab-1
16
Nimra Institute of Science and Technology
This plot shows pressure contours over flow field when NACA 0012 airfoil at =80
This plot shows velocity contours over flow field when NACA 0012 airfoil at =80
-
7/25/2019 Digital Simulation Lab-1
17/73
Allabakshu ShaikDigital Simulation Lab-1
17
Nimra Institute of Science and Technology
RESULTS
MACH NUMBER = 0.3
Angle of attack Coefficient of Lift Coefficient of Drag5 0.592 0.0022
8 0.919 0.0406
12 1.0583 0.1107
-
7/25/2019 Digital Simulation Lab-1
18/73
Allabakshu ShaikDigital Simulation Lab-1
18
Nimra Institute of Science and Technology
4. SIMULATION OF FLOW OVER 3D WING
Aim:To calculate the aerodynamic forces acting on the wing at different angle of attacks.
Software: Gambit and Fluent.
Procedure:
1. Create geometry in Gambit:
Create the geometry of aerofoil which is the cross sectional shape of wing.
Create the boundary for the aerofoil according to the following points.
Vertex X-
coordinate
Y-
coordinate
Z-
coordinate
A 4 4 0B 4 -4 0
C -3 -3 0
D -3 3 0
Join the vertices and create the face of the boundary.
Sweep the both faces (i.e. Airfoil and Boundary) with magnitude of 3 to obtainthe 3 dimensional wing and boundary.
Subtract the volume of airfoil from the boundary.
Thus the geometry to simulate the flow over a wing had been created.
2.
Mesh geometry:
Mesh the edges of the original faces of the airfoil and boundary.
First create the mesh for edges as follows:
Edges Successive ratio Interval count
Upper surface 1 60
Lower surface 1 60
AB 1 300
BC 1 300
CD 1 300DA 1 300
Select the Mesh face and click apply.
Thus the wing geometry with mesh had created as shown in fig below.
-
7/25/2019 Digital Simulation Lab-1
19/73
Allabakshu ShaikDigital Simulation Lab-1
19
Nimra Institute of Science and Technology
3. Specify boundary types: Create farfields as follows:
Faces Name
Face 5 Inlet
Face 6 Outlet
Face 2 & 9 Sides
Faces 3,4,7 & 8 Airfoil
Select Inlet as velocity inlet and name it as inlet.
Sides as wall and name it as sides. Outlet as Pressure oulet and name it as oulet.
Airfoil as wall and name it as airfoil.
Save the file.
Export the wing.msh file.
-
7/25/2019 Digital Simulation Lab-1
20/73
Allabakshu ShaikDigital Simulation Lab-1
20
Nimra Institute of Science and Technology
4. Set problem in Fluent:
Start Fluent, select 3ddp and click run.
Import wing.msh file from Main menu-File-Read-Case.
Data is displayed relating boundary types and zones of the flow field.
Select GridInfoSize then data is displayed.
Select GridScaleScaleok.
Select numerical scheme define the model properties as follows
Definemodelsolvero Solversegregated
o Space3do
Velocity formulationAbsoluteo
Formulationimplicito Timesteadyok
Definemodel - viscousK-(2D equation) ok
DefinemodelEnergy - turned off.
Define - Materialso Name - air
o Type of material - fluido
change/create.
Define - operating conditions
o
Operating pressure (pascal) = 0ok
Define-Boundary conditions
ZoneInletvelocity inlet
Velocity specification methodMagnitude and
Direction. Reference frame is Absolute.
Velocity magnitude = 102(m/s). For angle of attack = 0
0
X-comp = 1 and Y-comp = 0
angle of attack = 50
X-comp =0.99619 and Y-comp =0.087155angle of attack = 150
X-comp = 0.96592 and Y-comp = 0.25881
angle of attack = 200
X-comp =0.99619 and Y-comp =0.087155 Zoneoutlet Guage total pressure = 0 pa
Zonessides and airfoilwalladjacent zone
fluid.
-
7/25/2019 Digital Simulation Lab-1
21/73
Allabakshu ShaikDigital Simulation Lab-1
21
Nimra Institute of Science and Technology
5. Solve the problem:
SolveControls - solutionMomentum - second order upwind - ok
SolveIntialize - IntializeCompute from - Inlet - Init.
Solve - Monitors-Residual - convergence criteria = 1e-06
SolveMonitorsForcesOptionsprint and plot.
Wall zonesAirfoil.Coefficientlift, drag and moment - Apply.
Report-Reference valuescompute fromInletok
Filewritecase Solveiteratenumber of iterations = 1000 to get convergence
Filewritecase and data
6. Analyze results: PlotXY plot.
Change the Y-axis function to pressure followed by pressure coefficient.
Select surfaces.
Click on Plot.
Displaycontours
-
7/25/2019 Digital Simulation Lab-1
22/73
Allabakshu ShaikDigital Simulation Lab-1
22
Nimra Institute of Science and Technology
-
7/25/2019 Digital Simulation Lab-1
23/73
Allabakshu ShaikDigital Simulation Lab-1
23
Nimra Institute of Science and Technology
-
7/25/2019 Digital Simulation Lab-1
24/73
Allabakshu ShaikDigital Simulation Lab-1
24
Nimra Institute of Science and Technology
-
7/25/2019 Digital Simulation Lab-1
25/73
Allabakshu ShaikDigital Simulation Lab-1
25
Nimra Institute of Science and Technology
Conclusion:
1. Angle of attack =0
Cl =
Iterations Angle of
attack
Co-efficient of
lift
Co-efficient of
drag
Co-effiecient of
moment
345 0 0.00906 0.0067 0.00412
474 5 0.35337 0.05744 0.08701
849 15 1.4356 0.0151 0.3647
-
7/25/2019 Digital Simulation Lab-1
26/73
Allabakshu ShaikDigital Simulation Lab-1
26
Nimra Institute of Science and Technology
5.
SIMULATION OF COMPRESSIBLE FLOW IN A CONVERGENT-
DIVERGENT NOZZLE
Aim:To calculate the Static pressure at the nozzle inlet and outlet for the following conditions:
Consider the nozzle having a cross sectional area A varies with axial distance from the
throat, according to the formula A = 0.1+X2; where X varies from -0.5
-
7/25/2019 Digital Simulation Lab-1
27/73
Allabakshu ShaikDigital Simulation Lab-1
27
Nimra Institute of Science and Technology
9.
Specify boundary types: Go to Zones command button then specify boundary types.
Select edge, type of the edge and name of the edge as follows:
Edge Type Name
Left Pressure inlet Inlet
Right Pressure outlet Outlet
Top Wall Wall
Bottom Axis Centerline
Clicks apply.
Save the file and export 2d mesh file.
10.Set problem in Fluent:
Start Fluent, select 2ddp and click run.
Import CD nozzle.msh file from Main menu-File-Read-Case.
Data is displayed relating boundary types and zones of the flow field.
-
7/25/2019 Digital Simulation Lab-1
28/73
Allabakshu ShaikDigital Simulation Lab-1
28
Nimra Institute of Science and Technology
Select GridInfoSize then data is displayed.
Select GridScaleScaleok.
Select numerical scheme define the model properties as followsDefinemodelsolver
o Solversegregatedo
SpaceAxis symmetrico Velocity formulationAbsolute
o Formulationimplicito
Timesteadyok
Definemodel - viscousK-(2D equation) ok
DefinemodelEnergy - turned on.
Define - Materialso
Name - airo
Type of material - fluido DensityIdeal gaschange/create.
Define - operating conditionso Operating pressure (pascal) = 0ok
Define-Boundary conditions ZoneInletPressure inlet Guage total pressure = 101325pa
Supersonic/Intial gauge pressure99300pa Total temperature = 300K Under turbulence method select intensity and
hydraulic diameter set turbulence intensity = 1
Hydraulic diameter = 0.6677.o
Zone - farfield3 - pressure outlet
Gauge pressure (pa), this value changes according
to conditions in required in divergent section of
nozzle as follows:
(a)For Normal shock = 49650pa.(b)For supersonic flow = 24825pa
(c)
For subsonic flow = 198600pa Under turbulence method select intensity and
hydraulic diameter set turbulence intensity = 1
Hydraulic diameter = 0.6677.o
Zone - wall - wall.
Now the flow problem is ready to solve.
-
7/25/2019 Digital Simulation Lab-1
29/73
Allabakshu ShaikDigital Simulation Lab-1
29
Nimra Institute of Science and Technology
11.Solve the problem:
SolveControls - solutionMomentum - second order upwind - ok
SolveIntialize - IntializeCompute from - Inlet - Init.
Solve - Monitors-Residual - convergence criteria = 1e-06
Report-Reference valuescompute fromInletok
Filewritecase
Solveiteratenumber of iterations = 1000 to get convergence
Filewritecase and data
12.Analyze results:
PlotXY plot. Change the Y-axis function to pressure followed by pressure coefficient.
Select surfaces.
Click on Plot.
Display velocity - Machnumber contours in the nozzle
This plot shows the convergence of problem
-
7/25/2019 Digital Simulation Lab-1
30/73
Allabakshu ShaikDigital Simulation Lab-1
30
Nimra Institute of Science and Technology
SONIC THROAT AND NORMAL SHOCK IN DIVERGENT SECTION
Fig (a)
SONIC THROAT AND SUPERSONIC VELOCITY IN DIVERGENT SECTION
-
7/25/2019 Digital Simulation Lab-1
31/73
Allabakshu ShaikDigital Simulation Lab-1
31
Nimra Institute of Science and Technology
Fig (b)
SONIC THROAT SUBSONIC VELOCITY IN THE DIVERGENT SECTION
-
7/25/2019 Digital Simulation Lab-1
32/73
Allabakshu ShaikDigital Simulation Lab-1
32
Nimra Institute of Science and Technology
Fig (c)
-
7/25/2019 Digital Simulation Lab-1
33/73
Allabakshu ShaikDigital Simulation Lab-1
33
Nimra Institute of Science and Technology
RESULTS
1. From fig (a) it can be seen that normal shock is going to form at X = 0.3 along the axis of
nozzle.Static pressure at inlet = 96376.414pa
Static pressure at outlet = 49117.016pa
2. From fig (b) the flow is supersonic and isentropic in the divergent section.
Static pressure at inlet = 95918.297pa
Static pressure at outlet = 5584.5322pa
3. From fig (c) the flow is subsonic and isentropic in the divergent section.Static pressure at inlet = 97393.719pa
Static pressure at outlet = 188993.14pa
-
7/25/2019 Digital Simulation Lab-1
34/73
Allabakshu ShaikDigital Simulation Lab-1
34
Nimra Institute of Science and Technology
6.
INTRODUCTION TO MAT LAB
MATLAB is one of the most widely used computational tools in science and engineering.No matter what your backgroundbe it physics, chemistry, math, or engineeringit would
behoove you to at least learn the basics of this powerful tool. There are three good reasons to
learn a computational mathematics tool.
The first is that it serves as a background check for work you might be doing by hand. If
you are a student, its nice to have a back up that you can use to check your answe rs. I advise
that you dont become co-dependent on a computational tool or trust it as though it were anOracle. Do your work by hand when requested by your professors and just use MATLAB or any
other tool to check your work to make sure its correct.
The second reason is having a tool like MATLAB is priceless for generating plots and fordoing numerical methods. Instead of having to go through a tedious process of plotting
something by hand you can just have MATLAB generate any nice plot you desire.
Thirdly, the bottom line is that at some point in your career you will have to use a
computational mathematics tool. If youre a professor doing theoretical work, at one point or
another you are going to be working on a project where analytical solutions are not possible. Ifyou work in industry or in a national lab, chances are the work youre doing cant be done by
hand and will require a numerical solution. MATLAB is widely used in universities, in national
laboratories and at private companies. Knowing MATLAB will definitely be a plus on your
resume.
STARTING MAT LAB
To start the program, you select MATLAB (7.1). The default MATLAB desktop will
then open on your screen (see Figure 1-1). As shown in the . gure, the screen is divided into three
main elements. These are
File listing in the current directory
Command History Window
Command Window
The standard mix of menus appears on the top of the MATLAB desktop that allows you to dothings like, file management and debugging of files you create. You will also notice a drop-down
list on the upper right side of the desktop that allows you to select a directory to work in. The
most important item of business right now is the Command Window.
-
7/25/2019 Digital Simulation Lab-1
35/73
Allabakshu ShaikDigital Simulation Lab-1
35
Nimra Institute of Science and Technology
Figure 1-1 The MATLAB desktop
COMMAND WINDOW AND BASIC ARTHMITIC
The Command Window is found on the right-hand side of the MATLAB desktop. Commands are enteredat the prompt with looks like two successive greater than signs:
>>
Lets start by entering a few really basic commands. If you want to find the valueof a numericalexpression, simply type it in. Lets say we want to know the value of 433.12 multiplied by 15.7. We type433.12 * 15.7 at the MATLAB prompt and hit the enter key. The result looks like this:
>> 433.12*15.7
ans =
6.8000e+003
-
7/25/2019 Digital Simulation Lab-1
36/73
Allabakshu ShaikDigital Simulation Lab-1
36
Nimra Institute of Science and Technology
MATLAB comes with many basic or familiar mathematical quantities and functions built in.
How to use in an example.
The volume of a sphere is given by
V 4/33
Of course MATLAB comes with predefined. To use it, we just type pi. So afterdefining a variable to hold the radius, we can find the volume by typing
>> r = 2;
>> V = (4/3) *pi*r^3
V =
33.5103
Using of exponential function. That is, e = . We can reference e in MATLAB bytyping exp(a) which gives us the value of ea. Here are a few quick examples
>> exp(1)
ans =
2.7183
To find the square root of a number, we typesqrt. For example>> x = sqrt(9)
x =
3
>> y = sqrt(11)
y =
3.3166
To find the natural log of a numberx, type log(x).>> log(3.2)
ans =
1.1632>> x = 5; log(5)
ans =
1.6094
If you want the base ten logarithm, type log10(x)>> x = 3; log10(x)
ans =
0.4771
-
7/25/2019 Digital Simulation Lab-1
37/73
Allabakshu ShaikDigital Simulation Lab-1
37
Nimra Institute of Science and Technology
Using Trignometric functions
MATLAB comes equipped with the basic trig functions and their inverses,
taking radian argument by default. These are typed in lower case using the standardnotation. For instance>> cos(pi/4)
ans =
0.7071
To use an inverse of a trig function, add on an a before the name of the trigonometric
function. For example, to compute the inverse tangent of a number we can use the
following>> format rat
>> atan(pi/3)
ans =
1110/1373
Complex NumbersWe can also enter complex numbers in MATLAB. To remind members of our audiencewho are Aggie graduates, the square root of1 is defined as
i 1
A complex number is one that can be written in the form z = x +iy, where x is the real
part of z and y is the imaginary part of z. It is easy to enter complex numbers in
MATLAB, by default it recognizes i as the square root of minus one. We can docalculations with complex numbers in MATLAB pretty easily. For example
a 2 3i
b 1 i
a b 3 2i
Lets verify this in MATLAB. It is not necessary to add spaces or include amultiplication
symbol (*) when typing i in MATLAB.
>> format short
>> a = 2 + 3i;
>> b = 1 - i;
>> c = a + b
c =
3.0000 + 2.0000i
-
7/25/2019 Digital Simulation Lab-1
38/73
Allabakshu ShaikDigital Simulation Lab-1
38
Nimra Institute of Science and Technology
SAVING THE FILE:
MATLAB wouldnt be that useful if you couldnt save and retrieve your work right? Lets
say you want to save all the expressions and variables you have entered in the command window
for use at a later time. You can do this by executing the following actions:
1. Click on the File pull-down menu
2. Select Save Workspace As
3. Type in a . le name
4. Click on the Save button
This method creates a MATLAB file which has a .MAT file extension in Windows. Ifyou save a file this way, you can retrieve all the commands in it and work with it again just like
you can when working with files in any other computer program.
Sometimes, especially when working on complicated projects, you wont wantto sit thereand type every expression in a command window. It might be more appropriate to type a long
sequence of operations and store them in a . le that can be executed with a single command in the
command window. This is done by creating a script file. This type of file is known as a
MATLAB program and is saved in a file format with a .M extension. For this reason, we also
call them M-files. We can also create M-files that arefunction files.From what weve done so far, you already know how to create a script file. All a script file
comes down to is a saved sequence of MATLAB commands. Lets createa simple script . le thatwill compute ex for a few values ofx. First, open the MATLAB editor. Either
Click New M-File under the File pull-down menu
Or click on the New File icon on our toolbar at the top of the screen
Now type in the following lines:
% script file example1.m to compute exponential of a set of numbers
x = [1:2:3:4];
y = exp(x)Notice the first line begins with a % sign. This line is a comment. This is a line of text
that is there for our benefit, its a descriptive note that MATLAB ignores. The next line createsan array or set of numbers. An array is denoted using square braces [] and by delimiting the
elements of the array with colons or commas. The final line will tell MATLAB to calculate the
exponential of each member of the array, in other words the values e1, e2, e3, e4.
-
7/25/2019 Digital Simulation Lab-1
39/73
Allabakshu ShaikDigital Simulation Lab-1
39
Nimra Institute of Science and Technology
Save the file by clicking the Save icon in the file editor or by selecting Save As from theFile pull-down menu.
Save the file as example1.m in your MATLAB directory.
Now return to the MATLAB desktop command window. Type in example1. If you did
everything right, then you will see the following output
>> example1y =
2.7183 7.3891 20.0855 54.5982
We can also use M-files to create and store data. For an example , lets create a set of
temperatures that we will store in a file. We do this by creating a list of temperatures in the fileeditor
temps = [32,50,65,70,85]
Now we save this as a file that well call TemperatureData.m. We store this file in theMATLAB directory. To access it in the command window, we just type the name of the . le.
MATLAB responds by spitting out the list of numbers:
>> TemperatureData
temps =
32 50 65 70 85
Now we can use the data by referring to the array name used in the file. Lets create
another set of numbers called Celsius that converts these familiar temps into the European style
Celsius temperatures we are so familiar with. This can be done with the following command
>> CelsiusTemps = (5/9) * (temps - 32)
CelsiusTemps =
0 10.0000 18.3333 21.1111 29.4444
VECTORS:
A vector is a one-dimensional array of numbers. MATLAB allows you to create column vectorsor row vectors. A column vector can be created in MATLAB by enclosing a set of semicolon
delimited numbers in square brackets. Vectors can have any number of elements. For example,to create a column vector with three elements we write:>> a = [2; 1; 4]
a =
21
4
-
7/25/2019 Digital Simulation Lab-1
40/73
Allabakshu ShaikDigital Simulation Lab-1
40
Nimra Institute of Science and Technology
To create a row vector, we enclose a set of numbers in square brackets but this time use a spaceor comma to delimit the numbers. For example:
>> v = [2 0 4]
v =2 0 4
Or using commas:
>> w = [1,1,9]
w =
In MATLAB, we represent the transpose operation with a single quote or tickmark ().
Taking the transpose of a column vector produces a row vector:
Now lets take the transpose of a row vector to produce a column vector:>> Q = [2 1 3]
Q =
2 1 3>> R = Q'
R =
21
3
It is also possible to add or subtract two vectors to produce another. In order to performthis operation the vectors must both be of the same type and the same length, so we can add two
column vectors together to produce a new column vector or we can add two row vectors to
produce a new row vector, for example. This can be done referencing the variables only, it is not
necessary for the user to list the components. For example, lets add two column vectorstogether:
>> A = [1; 4; 5];
>> B = [2; 3; 3];>> C = A + B
C =
37
8
Now lets subtract one row vector from another:
>> W = [3,0,3];>> X = [2,1,1];
>> Y = WXY =
1 1 2
VECTOR DOT AND CROSS PRODUCT:
-
7/25/2019 Digital Simulation Lab-1
41/73
Allabakshu ShaikDigital Simulation Lab-1
41
Nimra Institute of Science and Technology
In MATLAB, the dot product of two vectors a, b can be calculated using the dot(a,b)command. The dot product between two vectors is a scalar, i.e. its just a number. Lets compute
a simple example using MATLAB:
>> a = [1;4;7]; b = [2;1;5];
>> c = dot(a,b)
c =
33The dot product can be used to calculate the magnitude of a vector. All that needs to be done is
to pass the same vector to both arguments. Consider the vector in the last section:
>> J = [0; 3; 4];
Calling dot we obtain:>> dot(J,J)
ans =
25
Another important operation involving vectors is the cross product. To compute the cross
product, the vectors must be three dimensional. For example:>> A = [1 2 3]; B = [2 3 4];
>> C = cross(A,B)
C =
1 2 1
MATRICES:
A matrix is a two-dimensional array of numbers. To create a matrix in MATLAB, weenter each row as a sequence of comma or space delimited numbers, and then use semicolons to
mark the end of each row. For example, consider:
This matrix is entered in MATLAB using the following syntax:
>> A = [1,6; 7, 11];
Or consider the matrix:
Multiplication:
-
7/25/2019 Digital Simulation Lab-1
42/73
Allabakshu ShaikDigital Simulation Lab-1
42
Nimra Institute of Science and Technology
Consider two matrices A and B. If A is an m p matrix and B is a p n matrix, they can bemultiplied together to produce an m n matrix. To do this in MATLAB, we leave out the period
(.) and simply write A*B. Keep in mind that if the dimensions of the two matrices are not
correct, the operation will generate an error. Lets consider two matrices:
These are both 2 2 matrices, so matrix multiplication is permissible. First, lets do array
multiplication so we can see the difference:
>> A = [2 1; 1 2]; B = [3 4; 5 6];>> A.*B
ans =6 45 12
Now we leave out the . character and execute matrix multiplication, which produces quite a
different answer:
>> A*Bans =
11 14
13 16The identity matrix is a square matrix that has ones along the diagonal and zeros elsewhere. To
create an
n x nidentity matrix, type the following MATLAB command: eye(n)Lets create a 4 4 identity matrix:>> eye(4)
ans =
1 0 0 00 1 0 0
0 0 1 0
0 0 0 1
DETERMINANTS:
The determinant of a square matrix is a number. For a 2 x 2 matrix, the determinant is given by:
To calculate the determinant of a matrix A in MATLAB, simply write det(A). Here is the
determinant of a 2 x 2 matrix:
>> A = [1 3; 4 5];
-
7/25/2019 Digital Simulation Lab-1
43/73
Allabakshu ShaikDigital Simulation Lab-1
43
Nimra Institute of Science and Technology
>> det(A)ans =
7
In this example, we find the determinant of a 4 x 4 matrix:>> B = [31 2 4; 0 2 1 8;9 17 11 3; 1 2 33];
>> det(B)
ans =
533INVERSE OF A MATRIX AND SOLVIND LINEAR EQUATIONS:
The inverse of a matrix Ais denoted by A-1
such that the following relationship is satisfied:
AA-1
= A-1
A = 1
Consider the following matrix equation:
Ax = b
If the inverse ofA exists, then the solution can be readily written as:
x = A-1b
In practice, this is much harder than it looks because computing the inverse of a matrix can be a
tedious pain. Luckily MATLAB makes things easy for us by doing all of the tedious work we
want to avoid. The inverse of a matrixA can be calculated in MATLAB by writing:inv(A)
The inverse of a matrix does not always exist. In fact, we can use the determinant to determine
whether or not the inverse exists. If det(A) = 0, then the inverse does not exist and we say thematrix issingular.
Lets get started by calculating a few inverses just to see how easy this is to do in
MATLAB. Starting with a simple 2 x 2 matrix:
First lets check the determinant ofA to ensure that the inverse exists:
>> det(A)
ans =6
Since the inverse exists, we can generate the solution readily in MATLAB:
>> x = inv(A)*bx =
1.0000
4.0000
-
7/25/2019 Digital Simulation Lab-1
44/73
Allabakshu ShaikDigital Simulation Lab-1
44
Nimra Institute of Science and Technology
PLOTTING AND GRAPHICS:Lets start with the most basic type of plot we can create, the graph ofa function of one variable.
Plotting a function in MATLAB involves the following three steps:
1. Defi ne the function2. Specify the range of values over which to plot the function3. Call the MATLAB plot(x,y) function
Lets plot the functiony = cos(x) over the range 0 x 10. To start, we want to define this intervaland tell MATLAB what increment to use. The interval is defined using square brackets [] that are filled in
the following manner:[ start : interval : end ]
Hence to ploty = cos(x), we enter the following commands:>> x = [0:0.1:10];
>> y = cos(x);
>> xlabel(x),ylabel(y);
Now we can plot the function. This is done by entering the following command:>> plot(x, y)
After typing the plot command, hit the enter key. After a moment MATLAB will open a newwindow on the screen with the captionFigure 1. The plot is found in this window.
Fplot:
-
7/25/2019 Digital Simulation Lab-1
45/73
Allabakshu ShaikDigital Simulation Lab-1
45
Nimra Institute of Science and Technology
The function fplot gets around our choice of interval used to generate the plot, and insteaddecides the number of plotting points to use for us. Generally, fplot will allow you to generate the most
accurate plots possible, but it also helps us get around errors like these. The formal call to fplot goes like
fplot (function string, [xstart,xend]). The argumentfunction string tells fplot the function you want toplot whilexstart andxend define the range over which to display the plot. This is pretty straightforward,lets see how it works out in the current example. We can do it all in one go by typing the followingcommand and hitting the enter key:
>> fplot('exp(-2*t)*sin(t)',[0, 4]);
MATLAB quickly produces the plot shown in Figure. If we want to add labels and a title to the plot, wecan follow the same procedure used with plot(x,y). Lets try it again this time adding our title Damped
Spring Forcing and labeling our axes:
>> fplot('exp(2*t)*sin(t)',[0,4]), xlabel('t'), ylabel('f(t)'),
title('Damped Spring Forcing')
MULTIPLE FUNCTIONS, ADDING LEGENDS AND COLOURS IN ONE PLOT:In many cases, it is necessary to plot more than one curve on a single graph. The
procedure used to do this in MATLAB is fairly straightforward. Lets start by showing two
functions on the same graph. In this case lets plot the following two functions over 0 t 5:f(t) = e
-t
g(t) = e-2t
We will differentiate between the two curves by plottingg with a dashed line.
-
7/25/2019 Digital Simulation Lab-1
46/73
Allabakshu ShaikDigital Simulation Lab-1
46
Nimra Institute of Science and Technology
Following the usual procedure, we first define our interval:
>> t = [0:0.01:5];
Next, we define the two functions:>> f = exp(t);
>> g = exp(2*t);
To plot multiple functions, we simply call the plot(x, y) command with multiple pairsx, y defining the
independent and dependent variables used in the plot in pairs. This is followed by a character stringenclosed in single quotes to tell us what kind of line to use to generate the second curve. In this case wehave:>> plot(t,f,t,g,'--')
This tells MATLAB to generate plots off(t) andg(t) with the latter function displayed as a dashed line.Note that while we cant show it in the book, MATLAB displays each curve with a unique color.
The color of each curve can be set automatically by MATLAB or we can manually select which color wewant. This is done by enclosing the appropriate letter assigned to each color used by MATLAB in singlequotes immediately after the function to be plotted is specified.
Color Specifier
White w
Black k
Red r
Cyan c
Green gMagneta m
Yellow y
The legend command is simple to use. Just add it to the line used for the plot(x, y) command and add atext string enclosed in single quotes for each curve you want to label. In our case we have:>> legend('sinh(x)','cosh(x)')
-
7/25/2019 Digital Simulation Lab-1
47/73
Allabakshu ShaikDigital Simulation Lab-1
47
Nimra Institute of Science and Technology
-
7/25/2019 Digital Simulation Lab-1
48/73
Allabakshu ShaikDigital Simulation Lab-1
48
Nimra Institute of Science and Technology
1.
BASIC MATHEMATICS
1. Solve >> 5*(11/14)
ans =3.9286
2. Solve
>> 5*(8/3)+3^7
ans =
2.2003e+003
3. Solve >> 9^1.25
ans =
15.5885
4. True or False. Ify has not been assigned a value, MATLAB will allow you to define the
equationx = y ^2 to store in memory for later use.
>> x=y^2;
??? Undefined function or variable 'y'.
Hence statement is False.
5.
If the volume of a cylinder of height h and radius r is given by V r2h,use MATLAB to . nd the volume enclosed by a cylinder that is 12 cm high
with a diameter of 4 cm.
>> r=2;
>> h=12;>> V=h*pi*r^2
-
7/25/2019 Digital Simulation Lab-1
49/73
Allabakshu ShaikDigital Simulation Lab-1
49
Nimra Institute of Science and Technology
V =150.7964
6. Use MATLAB to compute the sin of expressed as a rational number.
>> sin(pi/3)
ans =
0.8660
7.
Create a MATLAB m . le to display the results of sin(), sin(), sin() as rationalnumbers.
Select FileNewMfile
A new file named Editor is opened as shown below:
Save the file and run the file then results are displayed in command window as follows:ans =
0.8660
ans =
0.7071
-
7/25/2019 Digital Simulation Lab-1
50/73
Allabakshu ShaikDigital Simulation Lab-1
50
Nimra Institute of Science and Technology
ans =
1
-
7/25/2019 Digital Simulation Lab-1
51/73
Allabakshu ShaikDigital Simulation Lab-1
51
Nimra Institute of Science and Technology
2.
VECTORS AND MATRICES
1. Find the magnitude of the vector A (1 7 3 2).
>> A=[-1;7;3;2];>> A.*A
ans =
1
49
94
>> a = sum(A.*A)
a =
63
>> mag = sqrt(a)
mag =
7.9373
2. Find the magnitude of the vector A (1 i 7i 3 22i).
>> A=[-1+i;7i;3;-2-2i];>> A.*A
ans =
0 - 2.0000i
-49.0000
9.0000
0 + 8.0000i
>> a = sum(A.*A)
a =
-
7/25/2019 Digital Simulation Lab-1
52/73
Allabakshu ShaikDigital Simulation Lab-1
52
Nimra Institute of Science and Technology
-40.0000 + 6.0000i
>> mag = sqrt(a)
mag =
0.4730 + 6.3422i
3. Consider the numbers 1, 2, 3. Enter these as components of a column vector and ascomponents of a row vector.
>> a = [1 2 3]
a =
1 2 3
>> a = [1;2;3]
a =
1
23
4. Given A = [1; 2; 3]; B = [4; 5; 6]; find the array product of the two vectors.
>> A=[1;2;3],B=[4;5;6]
A =
1
2
3
B =
4
56
-
7/25/2019 Digital Simulation Lab-1
53/73
Allabakshu ShaikDigital Simulation Lab-1
53
Nimra Institute of Science and Technology
>> A.*B
ans =
410
18
5. What command would create a 5x5 matrix with ones on the diagonal and zeroseverywhere else?
>> eye(5)
ans =
1 0 0 0 00 1 0 0 0
0 0 1 0 0
0 0 0 1 00 0 0 0 1
6. Consider the two matricesA= , B and compute their array
product and matrix product.
>> A=[8 7 11;6 5 -1;0 2 -8],B=[2 1 2;-1 6 4;2 2 2]
A =
8 7 116 5 -1
0 2 -8
B =
2 1 2
-1 6 42 2 2
>> A.*B %Gives array product%
ans =
16 7 22
-
7/25/2019 Digital Simulation Lab-1
54/73
Allabakshu ShaikDigital Simulation Lab-1
54
Nimra Institute of Science and Technology
-6 30 -40 4 -16
>> A*B %Gives matrix product%
ans =
31 72 665 34 30
-18 -4 -8
Suppose thatA Use it to createB
Defining matrix %
F
F
8. Find a solution to the following set of equations:
x 2y 3z = 124x y 2z = 13
9y 8z = 1What is the determinant of the coefficient matrix?
>> A=[1 2 3;-4 1 2;9 0 -8],B=[12;13;-1]
-
7/25/2019 Digital Simulation Lab-1
55/73
Allabakshu ShaikDigital Simulation Lab-1
55
Nimra Institute of Science and Technology
A =1 2 3
-4 1 2
9 0 -8
B =
12
13-1
>> c=[A B]
c =1 2 3 12
-4 1 2 13
9 0 -8 -1
>> rank (A)
ans =3
>> rank (c)
ans =3
>> X=A\B
X =-1.7619
9.6667
-1.8571
>> det (A)
ans =-63
9. Does a solution to the following system exist? What is it?
x 2y 3z = 1
x 4y 3z = 2
2x 8y z =
>> A = [ 1 -2 3 ; 1 4 3 ; 2 8 1] , B = [ 1 ; 2 ; 3 ]
A =
1 -2 3
1 4 3
-
7/25/2019 Digital Simulation Lab-1
56/73
Allabakshu ShaikDigital Simulation Lab-1
56
Nimra Institute of Science and Technology
2 8 1
B =1
2
3
>> det(A)
ans =
-30 % since determinant is not equal to zero solution exist %
>> X = inv (A) *B
X =0.7333
0.1667
0.2000
10.Use LU decomposition to find a solution to the system:
x 7y 9z = 12
x y 4z = 16
x y 7z = 16
>> A = [1 7 -9; 2 -1 4; 1 1 -7], B = [ 12; 16; 16]
A =
1 7 -92 -1 4
1 1 -7
B =
12
16
16
>> [L, U] = lu(A)
L =0.5000 1.0000 0
1.0000 0 0
0.5000 0.2000 1.0000
-
7/25/2019 Digital Simulation Lab-1
57/73
Allabakshu ShaikDigital Simulation Lab-1
57
Nimra Institute of Science and Technology
U =
2.0000 -1.0000 4.0000
0 7.5000 -11.00000 0 -6.8000
>> X = U\(L\B)
X =9.6078
-1.0196
-1.0588
-
7/25/2019 Digital Simulation Lab-1
58/73
Allabakshu ShaikDigital Simulation Lab-1
58
Nimra Institute of Science and Technology
3.
PLOTTING AND GRAPHICS
1.
Generate a plot of the tangent function over 0 x 1 labeling thex andy axes. Set theincrement to 0.1.
>> x = [0:0.1:1];>> y = tan(x);
>> plot ( x , y )
>> xlabel ( ' x ' ), ylabel ( ' tanx ' )
2. Show the same plot, with sin(x) added to the graph as a second curve.
>> x = [0:0.1:1];>> plot ( x, tan(x) )
>> hold on
>> plot ( x, sin(x) )
-
7/25/2019 Digital Simulation Lab-1
59/73
Allabakshu ShaikDigital Simulation Lab-1
59
Nimra Institute of Science and Technology
3. Create a row vector of data points to represent p x p with an increment of 0.2.
Represent the same line using linspace with 100 points and with 50 points.
>> x=[-pi:0.2:pi]
x =
Columns 1 through 9
-3.1416 -2.9416 -2.7416 -2.5416 -2.3416 -2.1416 -1.9416 -1.7416 -1.5416
Columns 10 through 18
-1.3416 -1.1416 -0.9416 -0.7416 -0.5416 -0.3416 -0.1416 0.0584 0.2584
Columns 19 through 27
0.4584 0.6584 0.8584 1.0584 1.2584 1.4584 1.6584 1.8584 2.0584
Columns 28 through 32
2.2584 2.4584 2.6584 2.8584 3.0584
>> linspace ( -pi, pi, 100) % 100 uniformly spaced points %
ans =Columns 1 through 9
-
7/25/2019 Digital Simulation Lab-1
60/73
Allabakshu ShaikDigital Simulation Lab-1
60
Nimra Institute of Science and Technology
-3.1416 -3.0781 -3.0147 -2.9512 -2.8877 -2.8243 -2.7608 -2.6973 -2.6339
Columns 10 through 18
-2.5704 -2.5069 -2.4435 -2.3800 -2.3165 -2.2531 -2.1896 -2.1261 -2.0627
Columns 19 through 27
-1.9992 -1.9357 -1.8723 -1.8088 -1.7453 -1.6819 -1.6184 -1.5549 -1.4915
Columns 28 through 36
-1.4280 -1.3645 -1.3011 -1.2376 -1.1741 -1.1107 -1.0472 -0.9837 -0.9203
Columns 37 through 45
-0.8568 -0.7933 -0.7299 -0.6664 -0.6029 -0.5395 -0.4760 -0.4125 -0.3491
Columns 46 through 54
-0.2856 -0.2221 -0.1587 -0.0952 -0.0317 0.0317 0.0952 0.1587 0.2221
Columns 55 through 63
0.2856 0.3491 0.4125 0.4760 0.5395 0.6029 0.6664 0.7299 0.7933
Columns 64 through 72
0.8568 0.9203 0.9837 1.0472 1.1107 1.1741 1.2376 1.3011 1.3645
Columns 73 through 81
1.4280 1.4915 1.5549 1.6184 1.6819 1.7453 1.8088 1.8723 1.9357
Columns 82 through 90
1.9992 2.0627 2.1261 2.1896 2.2531 2.3165 2.3800 2.4435 2.5069
Columns 91 through 99
2.5704 2.6339 2.6973 2.7608 2.8243 2.8877 2.9512 3.0147 3.0781
Column 100
-
7/25/2019 Digital Simulation Lab-1
61/73
Allabakshu ShaikDigital Simulation Lab-1
61
Nimra Institute of Science and Technology
3.1416
>> linspace(-pi,pi,50) % 50 uniformly spaced points %
ans =
Columns 1 through 9
-3.1416 -3.0134 -2.8851 -2.7569 -2.6287 -2.5005 -2.3722 -2.2440 -2.1158
Columns 10 through 18
-1.9875 -1.8593 -1.7311 -1.6029 -1.4746 -1.3464 -1.2182 -1.0899 -0.9617
Columns 19 through 27
-0.8335 -0.7053 -0.5770 -0.4488 -0.3206 -0.1923 -0.0641 0.0641 0.1923
Columns 28 through 36
0.3206 0.4488 0.5770 0.7053 0.8335 0.9617 1.0899 1.2182 1.3464
Columns 37 through 45
1.4746 1.6029 1.7311 1.8593 1.9875 2.1158 2.2440 2.3722 2.5005
Columns 46 through 50
2.6287 2.7569 2.8851 3.0134 3.1416
4. Generate a grid for a three-dimensional plot where 3 x 2 and 5 y 5. Use an
increment of 0.1. Do the same if 5 x 5 and 5 y 5 with an increment of 0.2 in
both cases.
>> [x,y]=meshgrid(-3:0.1:2,-5:0.1:5);
>> z=cos(x).*sin(y);
>> mesh(x,y,z),xlabel('x'),ylabel('y'),zlabel('z');
-
7/25/2019 Digital Simulation Lab-1
62/73
Allabakshu ShaikDigital Simulation Lab-1
62
Nimra Institute of Science and Technology
>> clear all;
>> [x,y]=meshgrid(-5:0.2:5);
>> z=cos(x).*sin(y);
>> mesh(x,y,z),xlabel('x'),ylabel('y'),zlabel('z');
-
7/25/2019 Digital Simulation Lab-1
63/73
Allabakshu ShaikDigital Simulation Lab-1
63
Nimra Institute of Science and Technology
5. Plot the curvex = et cos t,y = et sin t, z = t using the plot3 function. Dont label theaxes, but turn on the grid.
>> t=meshgrid(0:0.1:1);
>> x=exp(-t)*cos(t);
>> y=exp(-t)*sin(t);
>> z=t;
>> mesh(x,y,z),xlabel('x'),ylabel('y'),zlabel('z');
-
7/25/2019 Digital Simulation Lab-1
64/73
Allabakshu ShaikDigital Simulation Lab-1
64
Nimra Institute of Science and Technology
-
7/25/2019 Digital Simulation Lab-1
65/73
Allabakshu ShaikDigital Simulation Lab-1
65
Nimra Institute of Science and Technology
4.
ALGEBRAIC EQUATIONS AND SYMBOLIC TOOLS
1.
Use MATLAB to enter 7- 5+ 5as a string, then find the numerical value.>> eq = '7*sqrt(2)-5*sqrt(60)+5*sqrt(8)'eq =
7*sqrt(2)-5*sqrt(60)+5*sqrt(8)
>> 7*sqrt(2)-5*sqrt(60)+5*sqrt(8)
ans =
-14.6882
2. Use MATLAB to solve 3+ 2x = 7.>> eq = '3*(x^2)+2*x=7'
eq =
3*(x^2)+2*x=7
>> s = solve (eq)
s =
-1/3+1/3*22^(1/2)-1/3-1/3*22^(1/2)
>> x = double(s(1))
x =
1.2301
>> y = double(s(2))
y =-1.8968
-
7/25/2019 Digital Simulation Lab-1
66/73
Allabakshu ShaikDigital Simulation Lab-1
66
Nimra Institute of Science and Technology
3. Findx such that + x .>> eq = 'x^2+sqrt(5)*x-pi=0'
eq =x^2+sqrt(5)*x-pi=0
>> s = solve(eq)
s =-1/2*5^(1/2)+1/2*(5+4*pi)^(1/2)
-1/2*5^(1/2)-1/2*(5+4*pi)^(1/2)
>> x=double(s)x =
0.9776
-3.2136
4. Find the solution of and symbolically plot the function for 2 > s = solve(eq)
s =
5/2
>> ezplot(eq)
-
7/25/2019 Digital Simulation Lab-1
67/73
Allabakshu ShaikDigital Simulation Lab-1
67
Nimra Institute of Science and Technology
5. Use solve to symbolically find the roots of 2 + 4t 6 = 0, then convert the answerinto numerical values.
>> eq = '2*t^3-t^2+4*t-6'
eq =
2*t^3-t^2+4*t-6
>> ezplot(eq)
>> s = solve (eq)
s =1/6*(289+6*2658^(1/2))^(1/3)-23/6/(289+6*2658^(1/2))^(1/3)+1/6
-1/12*(289+6*2658^(1/2))^(1/3)+23/12/(289+6*2658^(1/2))^(1/3)+1/6+1/2*i*3^(1/2)*
(1/6*(289+6*2658^(1/2))^(1/3)+23/6/(289+6*2658^(1/2))^(1/3))
-1/12*(289+6*2658^(1/2))^(1/3)+23/12/(289+6*2658^(1/2))^(1/3)+1/6-
1/2*i*3^(1/2)*(1/6*(289+6*2658^(1/2))^(1/3)+23/6/(289+6*2658^(1/2))^(1/3))
-
7/25/2019 Digital Simulation Lab-1
68/73
Allabakshu ShaikDigital Simulation Lab-1
68
Nimra Institute of Science and Technology
>> x= double(s)
x =
1.1162-0.3081 + 1.6102i
-0.3081 - 1.6102i
6. Find a solution of the system:
x 3y 2z = 6
2x 4y 3z = 8
3x 6y 8z = 5
>> s = solve ( 'x-3*y-2*z=6', '2*x-4*y-3*z=8', '-3*x+6*y+8*z=-5' );
>> x = s.xx =
1
>> y = s.yy =
-3
-
7/25/2019 Digital Simulation Lab-1
69/73
Allabakshu ShaikDigital Simulation Lab-1
69
Nimra Institute of Science and Technology
>> z = s.zz =
2
-
7/25/2019 Digital Simulation Lab-1
70/73
Allabakshu ShaikDigital Simulation Lab-1
70
Nimra Institute of Science and Technology
5. NUMERICAL SOLUTIONS OF ODEs
1.
Find a solution of the system: = = (0) = (0) = 1Now we create a function to implement this system in the M file:function xdot = eqx(t,x); %allocate array to store data%
xdot = zeros(2,1);
xdot(1) = x(2);
xdot(2) =x(1);
>>[t,x] = ode45 ( 'eqx' , [0,10], [1,1]); %('func_name', [start_time, end_time],y(0))%
>> plot (t, x(:,1), t, x(:,2), '--') %We access the fi rst function with x(:,1) and the secondby writing x(:,2) %
>> xlabel('x1'),ylabel('x2')
-
7/25/2019 Digital Simulation Lab-1
71/73
Allabakshu ShaikDigital Simulation Lab-1
71
Nimra Institute of Science and Technology
2. Solve:
= 2.3y, y(0) = 0Now we create a function to implement this system in the M file:
function ydot = eqy(t,y)
ydot = -2.3*y;
>> [t,y] = ode23('eqy',[-5,5],0);
>> plot(t,y),xlabel('t'),ylabel('y')
3. Use ode23 and ode45 to solve:
=y, y(0) = 1Now we create a function to implement this system in the M file:
function ydot = eqyd(t,y)ydot = y;
>> [t,y] = ode23('eqyd',[-5,5],1);
-
7/25/2019 Digital Simulation Lab-1
72/73
Allabakshu ShaikDigital Simulation Lab-1
72
Nimra Institute of Science and Technology
>> plot(t,y),xlabel('t'),ylabel('y1')
>> [t,y] = ode45('eqyd',[-5,5],1);
>> plot(t,y),xlabel('t'),ylabel('y1')
-
7/25/2019 Digital Simulation Lab-1
73/73
Allabakshu ShaikDigital Simulation Lab-1
73