Modelling, Simulation And Control In MATLAB

2y ago
18 Views
2 Downloads
1.44 MB
94 Pages
Last View : 23d ago
Last Download : 3m ago
Upload by : Braxton Mach
Transcription

Modelling, Simulationand Control in MATLABHans-Petter Halvorsenhttps://www.halvorsen.blog

Modelling, Simulation andControl in MATLAB

University of South-Eastern NorwayMATLABModelling, Simulation & ControlHans-Petter Halvorsen, 2019.08.06http://www.halvorsen.blog

PrefaceCopyright You cannot distribute or copy this document withoutpermission from the author. You cannot copy or link to this documentdirectly from other sources, web pages, etc. You should always link to theproper web page where this document is located, typicallyhttp://www.halvorsen.blogIn this MATLAB Course, you will learn basic MATLAB and how to useMATLAB in Control and Simulation applications. An introduction toSimulink and other Tools will also be given.MATLAB is a tool for technical computing, computation and visualization inan integrated environment. MATLAB is an abbreviation for MATrixLABoratory, so it is well suited for matrix manipulation and problemsolving related to Linear Algebra, Modelling, Simulation and Controlapplications.This is a self-paced course based on this document and some short videoson the way. This document contains lots of examples and self-paced tasksthat the users will go through and solve on their own. The user may gothrough the tasks in this document in their own pace and the instructorwill be available for guidance throughout the course.The MATLAB Course consists of 3 parts:1. Introduction to MATLAB2. Modelling, Simulation and Control3. Simulink and Advanced TopicsIn Part 2 of the course you will learn how to use MATLAB in Modelling,Control and Simulation.You must go through MATLAB Course – Part 1: Introduction to MATLABbefore you start.The course consists of lots of Tasks you should solve while reading thiscourse manual and watching the videos referred to in the text.ii

Make sure to bring your headphones for the videos in thiscourse. The course consists of several short videos that will give you anintroduction to the different topics in the course.PrerequisitesYou should be familiar with undergraduate-level mathematics and haveexperience with basic computer operations.What is MATLAB? MATLAB is a tool for technical computing, computationand visualization in an integrated environment. MATLAB is an abbreviationfor MATrix LABoratory, so it is well suited for matrix manipulation andproblem solving related to Linear Algebra.MATLAB is developed by The MathWorks. MATLAB is a short-term forMATrix LABoratory. MATLAB is in use world-wide by researchers anduniversities. For more information, see www.mathworks.comFor more information about MATLAB, etc., please visithttp://www.halvorsen.blogOnline MATLAB ts/programming/matlab/MATLAB ming/matlab/matlab basics.phpModelling, Simulation and Control with ming/matlab/matlab mic.phpiii

MATLAB atlab basics videos.phpMATLAB for ing/courses/matlab.phpOn these web pages you find video solutions, complete step by stepsolutions, downloadable MATLAB code, additional resources, etc.iv

Table of ContentsPreface . iiTable of Contents. v1Introduction . 12Differential Equations and ODE Solvers . 22.1ODE Solvers in MATLAB . 4Task 1: Bacteria Population . 5Task 2: Passing Parameters to the model. 6Task 3: ODE Solvers . 72.1.1Higher order differential equations . 8Task 4: 2. order differential equation . 103Discrete Systems . 123.1Discretization . 12Task 5: Discrete Simulation . 15Task 6: Discrete Simulation – Bacteria Population . 15Task 7: Simulation with 2 variables . 163.24Code Optimization . 16Numerical Techniques . 214.1Interpolation . 21Task 8: Interpolation . 234.2Curve Fitting . 244.2.1Linear Regression . 24Task 9: Linear Regression . 26v

viTable of Contents4.2.2Polynomial Regression . 27Task 10: Polynomial Regression. 29Task 11: Model fitting . 294.3Numerical Differentiation . 30Task 12: Numerical Differentiation . 344.3.1Differentiation on Polynomials . 35Task 13: Differentiation on Polynomials . 36Task 14: Differentiation on Polynomials . 364.4Numerical Integration . 36Task 15: Numerical Integration . 404.4.1Integration on Polynomials . 41Task 16: Integration on Polynomials . 415Optimization . 42Task 17: Optimization . 45Task 18: Optimization - Rosenbrock's Banana Function . 456Control System Toolbox . 477Transfer Functions . 497.1Introduction . 49Task 19: Transfer function . 517.2Second order Transfer Function . 52Task 20: 2.order Transfer function . 52Task 21: Time Response . 537.3Analysis of Standard Functions . 54Task 22: Integrator . 54Task 23: 1. order system . 54Task 24: 2. order system . 55MATLAB Course - Part II: Modelling, Simulation and Control

viiTable of ContentsTask 25: 2. order system – Special Case . 568State-space Models . 578.1Introduction . 578.2Tasks . 59Task 26: State-space model . 59Task 27: Mass-spring-damper system . 59Task 28: Block Diagram . 608.3Discrete State-space Models . 61Task 29: Discretization . 629Frequency Response . 639.1Introduction . 639.2Tasks . 66Task 30: 1. order system . 66Task 31: Bode Diagram . 679.3Frequency response Analysis . 689.3.1Loop Transfer Function . 689.3.2Tracking Transfer Function . 689.3.3Sensitivity Transfer Function. 69Task 32: Frequency Response Analysis . 709.4Stability Analysis of Feedback Systems . 71Task 33: Stability Analysis . 7310Additional Tasks . 74Task 34: ODE Solvers. 74Task 35: Mass-spring-damper system . 74Task 36: Numerical Integration . 75Task 37: State-space model . 76MATLAB Course - Part II: Modelling, Simulation and Control

viiiTable of ContentsTask 38: lsim . 76Appendix A – MATLAB Functions . 79Numerical Techniques . 79Solving Ordinary Differential Equations . 79Interpolation. 79Curve Fitting . 79Numerical Differentiation . 80Numerical Integration . 80Optimization . 80Control and Simulation . 81MATLAB Course - Part II: Modelling, Simulation and Control

1 IntroductionAdditional Resources, Videos, etc. are available ng/matlabPart 2: “Modelling, Simulation and Control” consists of the followingtopics: Differential Equations and ODE SolversDiscrete SystemsNumerical Techniqueso Interpolationo Curve Fittingo Numerical Differentiationo Numerical IntegrationOptimizationControl System ToolboxTransfer functionsState-space modelsFrequency Response1

2 Differential Equationsand ODE SolversMATLAB have lots of built-in functionality for solving differential equations.MATLAB includes functions that solve ordinary differential equations (ODE)of the form:𝑑𝑦 𝑓(𝑡, 𝑦),𝑑𝑡𝑦(𝑡0 ) 𝑦0MATLAB can solve these equations numerically.Higher order differential equations must be reformulated into a system offirst order differential equations.Note! Different notation is used:𝑑𝑦 𝑦 ′ 𝑦̇𝑑𝑡This document will use these different notations interchangeably.Not all differential equations can be solved by the same technique, soMATLAB offers lots of different ODE solvers for solving differentialequations, such as ode45, ode23, ode113, etc.Example:Given the following differential equation:𝑥̇ 𝑎𝑥1where 𝑎 𝑇 ,where 𝑇 is the time constantNote! 𝑥̇ 𝑑𝑥𝑑𝑡The solution for the differential equation is found to be:𝑥(𝑡) 𝑒 𝑎𝑡 𝑥0We shall plot the solution for this differential equation using MATLAB.2

3SolversDifferential Equations and ODESet 𝑇 5 and the initial condition 𝑥(0) 1.We will create a script in MATLAB (.m file) where we plot the solution 𝑥(𝑡)in the time interval 0 𝑡 25The Code is as follows:T 5;a -1/T;x0 1;t [0:1:25]x exp(a*t)*x0;plot(t,x);gridThis gives the following Results:[End of Example]This works fine, but the problem is that we first have to find the solutionto the differential equation – instead we can use one of the built-in solversfor Ordinary Differential Equations (ODE) in MATLAB. In the examples andtasks below we will learn how we can use these built-in ODE solvers.There are different functions, such as ode23 and ode45.MATLAB Course - Part II: Modelling, Simulation and Control

4Solvers2.1Differential Equations and ODEODE Solvers in MATLABAll of the ODE solver functions (ode23, ode45, etc.) share a syntax thatmakes it easy to try any of the different numerical methods, if it is notapparent which is the most appropriate. To apply a different method tothe same problem, simply change the ODE solver function name. Thesimplest syntax, common to all the solver functions, is:[t,y] solver(odefun,tspan,y0,options, )where “solver” is one of the ODE solver functions (ode23, ode45, etc.).Note! If you don’t specify the resulting array [t, y], the function create aplot of the result.‘odefun’ is the function handler, which is a “nickname” for your functionthat contains the differential equations.Example:Given the following differential equation:𝑥̇ 𝑎𝑥where 𝑎 1𝑇,where 𝑇 is the time constantWe use 𝑇 5 and the initial condition 𝑥(0) 1.We use the ode23 solver in MATLAB for solving the differential equation(“runmydiff.m”):tspan [0 25];x0 1;[t,x] ode23(@mydiff,tspan,x0);plot(t,x)Where @mydiff is defined as a function like this (“mydiff.m”):function dx mydiff(t,x)a -1/5;dx a*x;Note! You have to implement it in 2 different m. files, one m. file whereyou define the differential equation you are solving, and another .m filewhere you solve the equation using the ode23 solver.MATLAB Course - Part II: Modelling, Simulation and Control

5SolversDifferential Equations and ODEThis gives the same results as shown in the previous example above andMATLAB have solved the differential equation for us (numerically).[End of Example]Task 1: Bacteria PopulationIn this task we will simulate a simple model of a bacteria population in ajar.The model is as follows:birth rate bxdeath rate px2Then the total rate of change of bacteria population is:𝑥̇ 𝑏𝑥 𝑝𝑥 2Set b 1/hour and p 0.5 bacteria-hourNote! 𝑥̇ 𝑑𝑥𝑑𝑡 Simulate (i.e., create a plot) the number of bacteria in the jar after 1hour, assuming that initially there are 100 bacteria present.How many bacteria are present after 1 hour?MATLAB Course - Part II: Modelling, Simulation and Control

6SolversDifferential Equations and ODE[End of Task]Task 2: Passing Parameters to the modelGiven the following system:𝑥̇ 𝑎𝑥 𝑏1where 𝑎 𝑇 ,where 𝑇 is the time constantIn this case we want to pass 𝑎 and 𝑏 as parameters, to make it easy tobe able to change values for these parameters.We set initial condition 𝑥(0) 1 and 𝑇 5.The function for the differential equation is:function dx mysimplediff(t,x,param)% My Simple Differential Equationa param(1);b param(2);dx a*x b;Then we solve and plot the equation using this code:tspan [0 25];x0 1;a -1/5;b 1;param [a b];[t,y] ode45(@mysimplediff, tspan, x0,[], param);plot(t,y)By doing this, it is very easy to changes values for the parameters 𝑎 and𝑏 without changing the code for the differential equation.Note! We need to use the 5. argument in the ODE solver function for this.The 4. argument is for special options and is normally set to “[]”, i.e., nooptions.The result from the simulation is:MATLAB Course - Part II: Modelling, Simulation and Control

7SolversDifferential Equations and ODE Write the code aboveTry also this techniqueon the following differential equation:𝑥̇ 𝑏𝑥 𝑝𝑥 2Set b 1/hour and p 0.5 bacteria-hourYou should also read more about the different solvers (ode34, ode 45,etc.) that exists in the Help system in MATLAB[End of Task]Task 3: ODE SolversUse the ode23 function to solve and plot the results of the followingdifferential equation in the interval [𝑡0 , 𝑡𝑓 ]:𝒘′ (𝟏. 𝟐 𝒔𝒊𝒏𝟏𝟎𝒕)𝒘 𝟎, 𝑡0 0, 𝑡𝑓 5, 𝑤(𝑡0 ) 1Note! 𝑤 ′ 𝑑𝑤𝑑𝑡[End of Task]MATLAB Course - Part II: Modelling, Simulation and Control

8SolversDifferential Equations and ODE2.1.1 Higher order differential equationsIn real life we typically have higher order differential equations, or wehave a set of 1. order differential equations that describe a given system.How can we solve such equations in MATLAB?Example:Given the differential equations:𝑑𝑦 𝑥𝑑𝑡𝑑𝑥 𝑦𝑑𝑡In MATLAB you define a function for these differential equations:function dy mydiff(t,y)dy(1) y(2);dy(2) -y(1);dy [dy(1); dy(2)];Note! Since numbers of equations is more than one, we need to usevectors!!Using the ode45 function gives the following code:[t,y] ode45(@mydiff, [-1,1], [1,1]);plot(t,y)title('solution of dy/dt x and dx/dt -y')legend('y', 'x')The equations are solved in the time span [ 1, 1] with initial values [1, 1].This gives the following plot:MATLAB Course - Part II: Modelling, Simulation and Control

9SolversDifferential Equations and ODENote! To make it more clearly, we can rewrite the equations (setting 𝑥1 𝑥, 𝑥2 𝑦):𝑑𝑥1 𝑥2𝑑𝑡𝑑𝑥2 𝑥1𝑑𝑡𝑥1𝑥̇Where we have the vector 𝑥 [𝑥 ] and 𝑥̇ [ 1 ]𝑥̇ 22or MATLAB “syntax”: 𝑑𝑥𝑑𝑡 𝑥̇In MATLAB it is tempting to define these 2 differential equations like this:dxdt1 -x2;dxdt2 x1;But if we have more than one differential equation (in this case wehave 2), we need to use vectors!So, it needs be like this:dxdt(1) -x(2);dxdt(2) x(1);The final code that implements the differential equations becomes(“mydiff.m”):MATLAB Course - Part II: Modelling, Simulation and Control

10SolversDifferential Equations and ODEfunction dxdt mydiff(t,x)dxdt(1) -x(2);dxdt(2) x(1);dxdt dxdt';Note! The function mydiff must return a column vector, that’s why weneed to transpose it.Then we use the ode solver to solve the differential equations(“run mydiff.m”):tspan [-1,1];x0 [1,1];[t,x] ode45(@mydiff, tspan, x0);plot (t,x)legend('x1', 'x2')The solution will be the same.[End of Example]Task 4: 2. order differential equationUse the ode23/ode45 function to solve and plot the results of the followingdifferential equation in the interval [𝑡0 , 𝑡𝑓 ]:(𝟏 𝒕𝟐 )𝒘̈ 𝟐𝒕𝒘̇ 𝟑𝒘 𝟐, 𝑡0 0, 𝑡𝑓 5, 𝑤(𝑡0 ) 0, 𝑤̇ (𝑡0 ) 1Note! 𝑤̈ 𝑑2 𝑤𝑑𝑡 2Note! Higher order differential equations must be reformulated into asystem of first order differential equations.Tip 1: Reformulate the differential equation so 𝑤̈ is alone on the left side.Tip 2: Set:𝑤 𝑥1𝑤̇ 𝑥2MATLAB Course - Part II: Modelling, Simulation and Control

11SolversDifferential Equations and ODE[End of Task]Example:Given the following differential equations:𝑥̇ 1 0.9𝑥1 0.1𝑥2 1𝑥̇ 2 0.4𝑥2 0.8𝑥3 0.9𝑥̇ 3 0.7𝑥1 0.1𝑥3MATLAB:function dxdt my3orderdiff(t,x)dxdt(1) -0.9*x(1) 0.1*x(2) 1;dxdt(2) -0.4*x(2) 0.8*x(3) - 0.9;dxdt(3) -0.7*x(1) - 0.1*x(3);dxdt dxdt';and the Script for running the simulation:clearclctspan [0,30];x0 [0,0,0];[t,x] ode23(@my3orderdiff, tspan, x0);plot (t,x)legend('x1', 'x2', 'x3')[End of Example]MATLAB Course - Part II: Modelling, Simulation and Control

3 Discrete SystemsMATLAB has built-in powerful features for simulation of continuousdifferential equations and dynamic systems.Sometimes we want to or need to discretize a continuous system and thensimulate it in MATLAB.When dealing with computer simulation, we need to create a discreteversion of our system. This means we need to make a discrete version ofour continuous differential equations. Actually, the built-in ODE solvers inMATLAB use different discretization methods. Interpolation, Curve Fitting,etc. is also based on a set of discrete values (data points ormeasurements). The same with Numerical Differentiation and NumericalIntegration, etc.Below we see a continuous signal vs the discrete signal for a given systemwith discrete time interval 𝑇𝑠 0.1𝑠.3.1DiscretizationIn order to discretize a continuous model there are lots of differentmethods to use. One of the simplest is Euler Forward method:𝑥̇ 𝑥𝑘 1 𝑥𝑘𝑇𝑠12

13Discrete Systemswhere 𝑇𝑠 is the sampling time.Lots of other discretization methods do exists, such as “Euler backward”,Zero Order Hold (ZOH), Tustin’s method, etc.As shown in a previous chapter, MATLAB have lots of built-in functions forsolving differential equations numerically, but here we will create our owndiscrete model.Example:Given the following differential equation:𝑥̇ 𝑎𝑥 𝑏𝑢Note!𝑥̇ is the same as𝑑𝑥𝑑𝑡Where:𝑥 - Process variable, e.g., Level, Pressure, Temperature, etc.𝑢 - Input variable, e.g., Control Signal from the Controller𝑎, 𝑏 - ConstantsWe start with finding the discrete differential equation.We can use e.g., the Euler Approximation:MATLAB Course - Part II: Modelling, Simulation and Control

14Discrete Systems𝑥̇ 𝑥𝑘 1 𝑥𝑘𝑇𝑠𝑇𝑠 - Sampling IntervalThen we get:𝑥𝑘 1 𝑥𝑘 𝑎𝑥𝑘 𝑏𝑢𝑘𝑇𝑠This gives the following discrete differential equation:𝑥𝑘 1 (1 𝑇𝑠 𝑎)𝑥𝑘 𝑇𝑠 𝑏𝑢𝑘Now we are ready to simulate the systemWe set 𝑎 0.25, 𝑏 2 and 𝑢 1 (You can explore with other values onyour own)The Code can be written as follows:% Simulation of discrete modelclear, clc% Model Parametersa 0.25;b 2;% Simulation ParametersTs 0.1; %sTstop 30; %suk 1; % Step Responsex(1) 0;% Simulationfor k 1:(Tstop/Ts)x(k 1) (1-a*Ts).*x(k) Ts*b*uk;end% Plot the Simulation Resultsk 0:Ts:Tstop;plot(k,x)grid onThis gives the following Results:MATLAB Course - Part II: Modelling, Simulation and Control

15Discrete Systems[End of Example]Task 5: Discrete SimulationGiven the following differential equation:𝑥̇ 𝑎𝑥1where 𝑎 𝑇 , where 𝑇 is the time constantNote! 𝑥̇ 𝑑𝑥𝑑𝑡Find the discrete differential equation and plot the solution for this systemusing MATLAB.Set 𝑇 5 and the initial condition 𝑥(0) 1.Create a script in MATLAB (.m file) where we plot the solution 𝑥(𝑘).[End of Task]Task 6: Discrete Simulation – Bacteria PopulationIn this task we will simulate a simple model of a bacteria population in ajar.MATLAB Course - Part II: Modelling, Simulation and Control

16Discrete SystemsThe model is as follows:birth rate bxdeath rate px2Then the total rate of change of bacteria population is:𝑥̇ 𝑏𝑥 𝑝𝑥 2Set b 1/hour and p 0.5 bacteria-hourWe will simulate the number of bacteria in the jar after 1 hour, assumingthat initially there are 100 bacteria present. Find the discrete model using the Euler Forward method by hand andimplement and simulate the system in MATLAB using a For Loop.[End of Task]Task 7: Simulation with 2 variablesGiven the following system𝑑𝑥1 𝑥2𝑑𝑡𝑑𝑥2 𝑥1𝑑𝑡Find the discrete system and simulate the discrete system in MATLAB.Solve the equations, e.g., in the time span [ 1 1] with initial values [1, 1].[End of Task]3.2Code OptimizationExample:When doing more advanced simulations, it is important that you spendtime optimization your code. In the examples and tasks above theequations are quite simple, but when the equations become moreMATLAB Course - Part II: Modelling, Simulation and Control

17Discrete Systemscomplicated, or your simulation time increases, code optimizationbecomes more important.In the code example below the following simple differential equation willbe used:𝑥̇ 𝑎𝑥 𝑏𝑢But we will increase the simulation time dramatically compared to theprevious examples.MATLAB Code 1;clear, clctica -10; b 0.5;x 0; u 1;dt 0.01;N 1000000000;X(1) x;for i 1:NX(i 1) X(i) dt*(a*X(i) b*u);endtocMATLAB Code 2:clear, clctica -10; b 0.5;x 0; u 1;dt 0.01;N 1000000000;X zeros(N,1);for i 1:NX(i 1) X(i) dt*(a*X(i) b*u);endtocMATLAB Code 3:clear, clcticMATLAB Course - Part II: Modelling, Simulation and Control

18Discrete Systemsa -10; b 0.5;x 0; u 1;dt 0.01;N 1000000000;X zeros(N,1);for i 1:NX(i) x;x x dt*(a*x b*u);endtocTry the different code examples and note the execution time. Try withdifferent values of N, etc.[End of Example]Example:In the code example below the following simple differential equation willbe used:𝑥̇ 𝑎𝑥 𝑏𝑢MATLAB Code 1;% Simulation of discrete modelclear, clc% Model Parametersa 0.25;b 2;% Simulation ParametersTs 0.01;Tstop 10000000;x(1) 0;N Tstop/Ts;u linspace(0,1,N);% Simulationticfor k 1:Nx(k 1) (1-a*Ts).*x(k) Ts*b*u(k);endtoc% Plot the Simulation Resultst 0:Ts:Tstop;plot(t,x)MATLAB Course - Part II: Modelling, Simulation and Control

19Discrete Systemsgrid onMATLAB Code 2:% Simulation of discrete modelclear, clc% Model Parametersa 0.25;b 2;% Simulation ParametersTs 0.01;Tstop 10000000;uk 1;N Tstop/Ts;u linspace(0,1,N);%Preallocationx zeros(N,1);% Simulationticfor k 1:Nx(k 1) (1-a*Ts).*x(k) Ts*b*u(k);endtoc% Plot the Simulation Resultst 0:Ts:Tstop;plot(t,x)grid onMATLAB Code 3:% Simulation of discrete modelclear, clc% Model Parametersa 0.25;b 2;% Simulation ParametersTs 0.01;Tstop 10000000;uk 1;x 0;X(1) x;N Tstop/Ts;u rand(N,1);u linespace(0,1,N);% SimulationMATLAB Course - Part II: Modelling, Simulation and Control

20Discrete SystemsX zeros(N,1);ticfor k 1:Nx (1-a*Ts)*x Ts*b*u(k);X(k 1) x;endtoc% Plot the Simulation Resultst 0:Ts:Tstop;plot(t,X)grid onIn general, it will be many ways to implement a given system in MATLAB,we can use built in ODE solvers, we can use different discretizationmethods, and we can optimize our code in other ways.There is not a “best way” that can be used for all kind of systems. It willbe your responsibility to find the best solution for your system. That’s whyit is important that you know about different ways to do things, so you areable to find the best solution in a given situation.[End of Example]MATLAB Course - Part II: Modelling, Simulation and Control

4 Numerical TechniquesIn the previous chapter we investigated how to solve differential equationsnumerically, in this chapter we will take a closer look at some othernumerical techniques offered by MATLAB, such as interpolation, curvefitting, numerical differentiations and integrations.4.1InterpolationInterpolation is used to estimate data points between two known points.The most common interpolation technique is Linear Interpolation.In MATLAB we can use the interp1 function.Example:Given the following data:x012345y15109620We will find the interpolated value for 𝑥 3.5.The following MATLAB code will do this:x 0:5;y [15, 10, 9, 6, 2, 0];plot(x,y ,'-o')% Find interpolated value for x 3.5new x 3.5;new y interp1(x,y,new x)The answer is 4, from the plot below we see this is a good guess:21

22Numerical Techniques[End of Example]The default is linear interpolation, but there are other types available,such as: linearnearestsplinecubicetc.Type “help interp1” in order to read more about the different options.Example:In this example we will use a spline interpolation on the same data as inthe example above.x 0:5;y [15, 10, 9,6, 2, 0];new x 0:0.2:5;new y interp1(x,y,new x, 'spline')plot(x,y, new x, new y, '-o')MATLAB Course - Part II: Modelling, Simulation and Control

23Numerical TechniquesThe result is as we plot both the original point and the interpolated pointsin the same graph:We see this result in 2 different lines.[End of Example]Task 8: InterpolationGiven the following data:Temperature, T [ oC] Energy, u .44002967.95003131.6Plot u versus T. Find the interpolated data and plot it in the same graph.Test out different interpolation types. Discuss the results. What kind ofinterpolation is best in this case?What is the interpolated value for u 2680.78 KJ/kg?[End of Task]MATLAB Course - Part II: Modelling, Simulation and Control

244.2Numerical TechniquesCurve FittingIn the previous section we found interpolated points, i.e., we found valuesbetween the measured points using the interpolation technique. It wouldbe more convenient to model the data as mathematical function 𝑦 𝑓(𝑥).Then we could easily calculate any data we want based on this model.MATLAB has built-in curve fitting functions that allows us to create empiricdata model. It is important to have in mind that these models are goodonly in the region we have collected data.Here are some of the functions available in MATLAB used for curve fitting:FunctionpolyfitpolyvalDescriptionP POLYFIT(X,Y,N) finds the coefficients of apolynomial P(X) of degree N that fits the data Ybest in a least-squares sense. P is arow vectorof length N 1 containing the polynomialcoefficients in descending powers, P(1)*X N P(2)*X (N-1) . P(N)*X P(N 1).Evaluate polynomial. Y POLYVAL(P,X) returnsthe value of a polynomial P evaluated at X. P is avector of length N 1 whose elements are thecoefficients of the polynomial in descendingpowers. Y P(1)*X N P(2)*X (N-1) . P(N)*X P(N 1)Example polyfit(x,y,1)These techniques use a polynomial of degree N that fits the data Y best ina least-squares sense.A polynomial is expressed as:𝑝(𝑥) 𝑝1 𝑥 𝑛 𝑝2 𝑥 𝑛 1 𝑝𝑛 𝑥 𝑝𝑛 1where 𝑝1 , 𝑝2 , 𝑝3 , are the coefficients of the polynomial.MATLAB represents polynomials as row arrays containing coefficientsordered by descending powers.4.2.1 Linear RegressionHere we will create a linear model of our data on the form:𝑦 𝑎𝑥 𝑏MATLAB Course - Part II: Modelling, Simulation and Control

25Numerical TechniquesThis is actually a polynomial of 1.orderExample:Given the following data:x y0 151 1029364250We will find the model on the form:𝑦 𝑎𝑥 𝑏We will use the polyfit function in MATLAB.The following code will solve it:x [0, 1, 2, 3, 4 ,5];y [15, 10, 9, 6, 2 ,0];n 1; % 1.order polynomialp polyfit(x,y,n)The answer is:ans -2.914314.2857This gives the following model:𝑦 2.9143

MATLAB have lots of built-in functionality for solving differential equations. MATLAB includes functions that solve ordinary differential equations (ODE) of the form: ( , ), ( 0) 0 MATLAB can solve these equations numerically. Higher order differential equations must be reformulated into a syste

Related Documents:

tasks during combat operations: executing manoeuvre; conducting enemy reconnaissance; carrying firepower against the enemy, as well as making decisions to perform the above tasks. Such simulation modelling means can form the basis of simulation modelling means at higher levels of managem

NATO North Atlantic Treaty Organization . NMSG NATO Modelling and Simulation Group . NMSMP NATO Modelling and Simulation Master Plan . OCD Operational Concept Document . ORBAT Order of Battle . SIMCON Simulation Control . SISO Simulation Interoperability Stan dards Organization . SLA Service Level Agreement . SME Subject Matter Expert

and simplified method to describe masonry vaults in global seismic analyses of buildings. Fig. 1 summarizes three different modelling techniques for ma sonry modelling, respectively, mi cro- , macro- and simplified micro modelling. In the case a micro modelling approach is take n, the challenge is to describe the complex behavior of the

Agile Modelling is a concept invented in 1999 by Scott Ambler as a supplement to Extreme Pro-gramming (XP) [Source: Agile Modelling Values]. Strictly defined, Agile Modelling (AM) is a chaordic, practices-based methodology for effective modelling and documentation [Source: Interview with SA by Clay Shannon].

equately support part modelling, i.e. modelling of product elements that are manufactured in one piece. Modelling is here based on requirements from part-oriented applica-tions, such as a minimal width for a slot in order to be able to manufacture it. Part modelling systems have evolved for some time now, and different modelling concepts have

5. Who can grow the largest crystal from solution? Modelling crystals 15 . 1. Modelling a salt crystal using marshmallows 2. Modelling crystals using cardboard shapes 3. Modelling diamond and graphite 4. Modelling crystal growth using people. More about crystals 21 . 1. Crystalline or plastic? 2. Make a crystal garden. Putting crystals to use .

follow using state-of-the- art modeling tool of BPMN 2.0 and UML. Key words: Computer-aided systems Production logistics Business process modelling BPMN 2.0 UML Modelling techniques INTRODUCTION Business Process Execution Language for web Business Process Modelling (BPM) as the main core Business Process Modelling Notation (BPMN) to

Financial Statements Modelling www.bestpracticemodelling.com Page 5 of 40 Financial Statements Module Location 1.2. Financial Statements Modelling Overview The modelling of the financial statements components of an entity is a unique area of spreadsheet modelling, because it involves the systematic linking in of information from