MATLAB Examples. Simulink. Hans-Petter Halvorsen, M.Sc.

Similar documents
Introduction to Simulink

Control and Simulation in. LabVIEW

Introduction to Simulink. The Use of Mathematic Simulations in Electrical Engineering

University College of Southeast Norway MATLAB. Part III: Simulink and Advanced Topics. Hans-Petter Halvorsen,

Simulation in LabVIEW. Hans-Petter Halvorsen, M.Sc.

MATLAB Examples. Flow Control and Loops. Hans-Petter Halvorsen, M.Sc.

Introduction to ERwin

MATLAB Examples. Interpolation and Curve Fitting. Hans-Petter Halvorsen

Solutions. Discretization HANS-PETTER HALVORSEN,

Exercise: State-space models

University College of Southeast Norway. Control and Simulation. in LabVIEW. Hans-Petter Halvorsen,

Create a Virtual Test Environment

Virtual Instruments with LabVIEW

Visual Studio Team Services

Unit Testing. Quiz with Explainations. Hans-Petter Halvorsen, M.Sc.

Software Implementation

Using SQL Server in C#

Database Views & Stored Procedures. Hans-Petter Halvorsen, M.Sc.

Software Architecture

University College of Southeast Norway. LM-900 Level Tank. Hans-Petter Halvorsen,

NI mydaq HANS-PETTER HALVORSEN, Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics

Datalogging in LabVIEW

DAQ in MATLAB HANS-PETTER HALVORSEN,

State Estimation with Observers

Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics. MathScript

Programming. Languages & Frameworks. Hans-Petter Halvorsen, M.Sc. O. Widder. (2013). geek&poke. Available:

University College of Southeast Norway. Web Services. with Examples. Hans-Petter Halvorsen,

NI Vision System HANS- PETTER HALVORSEN,

Software Platforms. Quiz with Explainations. Hans-Petter Halvorsen, M.Sc.

UML. Quiz with Explainations. Hans-Petter Halvorsen, M.Sc.

Team Assignment. Final Software Delivery. IA4412 Software Engineering

Modeling Mechanical System using SIMULINK

Wireless DAQ using ZigBee

Matlab Handout Nancy Chen Math 19 Fall 2004

Mathematical Modelling Using SimScape (Mechanical Systems)

Example: Modeling a Cruise Control System in Simulink

Introduction to MATLAB

Software Architecture

dy = y, dt y(0) = 1, y(t) = e t.

Importing Models from Physical Modeling. Tools Using the FMI Standard

Team Foundation Server Visual Studio Team Services. Hans-Petter Halvorsen, M.Sc.

ChE 400: Applied Chemical Engineering Calculations Tutorial 6: Numerical Solution of ODE Using Excel and Matlab

Week Assignment. Source Code Control (SCC) & Bug Tracking Systems. Hans-Petter Halvorsen

C3 Numerical methods

2 SIMULATING A MODEL Simulink Tutorial

Introduction to Simulink

Tutorial 17 Workflow Graphical User Interface Figure 1

Lab 2 Modeling from an observed response

Raspberry Pi. Hans-Petter Halvorsen, M.Sc.

Create Installation Packages in Visual Studio

Introduction to Matlab Simulink. Control Systems

Experiment 8 SIMULINK

LabVIEW MathScript Quick Reference

Software Documentation

Introduction to Simulink. Todd Atkins

University College of Southeast Norway ASP.NET. Web Programming. Hans-Petter Halvorsen,

Database Systems. S. Adams. Dilbert. Available: Hans-Petter Halvorsen

Data Acquisition HANS-PETTER HALVORSEN,

UML. Unified Modeling Language. Hans-Petter Halvorsen, M.Sc. O. Widder. (2013). geek&poke. Available:

Modbus Hans-Petter Halvorsen

Data Acquisition in LabVIEW

Tutorial: Getting Started with the LabVIEW Simulation Module

Fall 2015 Math 337. Basic MatLab

Database. Quiz with Explainations. Hans-Petter Halvorsen, M.Sc.

What is Simulink. >>simulink

BME 5742 Bio-Systems Modeling and Control

Source Code Control. Quiz with Explainations. Hans-Petter Halvorsen, M.Sc.

SIMULINK Tutorial. Select File-New-Model from the menu bar of this window. The following window should now appear.

Sensors and Actuators with Arduino. Hans-Petter Halvorsen, M.Sc.

SQL Server and SQL Structured Query Language

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

Høgskolen i Telemark Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics.

Assignment Assignment for Lesson 9.1

Workpackage 5 - Ordinary Differential Equations

SIMULINK A Tutorial by Tom Nguyen

Software Testing. Hans-Petter Halvorsen, M.Sc.

Module 3: Graphing Quadratic Functions

Figure 1: Control & Simulation Loop

Note 10 Introduction to MATLAB & SIMULINK

Polymath 6. Overview

Source Code Control & Bug Tracking

Simulation of Mechatronic Systems

[ MATLAB ] [ Resources ] PART TWO: SIMULINK

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

NI USB-TC01 Thermocouple Measurement Device

Exercise 11: Discretization

Week Assignment Source Code Control (SCC) & Bug Tracking Systems Hans-Petter Halvorsen

2018, Controllab Products B.V. Author: Ir. C. Kleijn, Ir. M. A. Groothuis. Disclaimer

The Interpolating Polynomial

Industrial IT Laboratory Work Hans-Petter Halvorsen

Web Services Hans-Petter Halvorsen

Lecture 10: Simulink. What is Simulink?

Creating Classes and Libraries with Arduino

Experiment 6 SIMULINK

1 Basic Mathematical Operations

Graphical User Interface. GUI in MATLAB. Eng. Banan Ahmad Allaqta

Math 115 Second Midterm March 25, 2010

Core Mathematics 1 Graphs of Functions

Tutorial - Exporting Models to Simulink

Introduction to Simulink

Transcription:

MATLAB Examples Simulink Hans-Petter Halvorsen, M.Sc.

What is Simulink? Simulink is an add-on to MATLAB. You need to have MATLAB in order to use Simulink Simulink is used for Simulation of dynamic models In Simulink we create a Graphical Block Diagram for the system (based on the differential equations(s))

Simulink Model In Simulink we create and configure graphical blocks and wire them together (based on the differential equations)

Start Simulink from MATLAB Click the Simulink button in the Toolbar - or type simulink in the Command Window

Simulink Start Page

Simulink Model Editor Library Browser Start creating your Simulink Model here with blocks from the Simulink Library Browser (just Drag and Drop )

Simulink Library Browser

Simulink Example

Simulink Example II

Example Model: x = ax My First Simulink Model We start by drawing a simple Block Diagram for the model like this ( Pen & paper ): Where T is the Time constant We will use the following: We will create and simulate this block diagram with Simulink

Using ODE Solvers in MATLAB Step 1: Define the differential equation as a MATLAB function (mydiff.m): function dx = mydiff(t,x) T = 5; a = -1/T; dx = a*x; x0 Step 2: Use one of the built-in ODE solver (ode23, ode45,...) in a Script. clear clc tspan = [0 25]; x0 = 1; tspan [t,x] = ode23(@mydiff,tspan,x0); plot(t,x)

My First Simulink Model

Solution My First Simulink Model Start the Simulation by clicking this icon Set Initial Value Simulation Time See the Simulation Results Double-Click on the different Blocks to enter values

Bacteria Population Here we will simulate a simple model of a bacteria population in a jar. The model is as follows: birth rate=bx death rate = px 2 Then the total rate of change of bacteria population is: x = bx px * Set b=1/hour and p=0.5 bacteria-hour We will simulate the number of bacteria in the jar after 1 hour, assuming that initially there are 100 bacteria present.

In MATLAB We would do like this function dx = bacteriadiff(t,x) % My Simple Differential Equation b=1; p=0.5; dx = b*x - p*x^2; clear clc tspan=[0 1]; x0=100; [t,y]=ode45(@bacteriadiff, tspan,x0); plot(t,y) [t,y]

Block Diagram for the Model ( Pen and Paper )

Simulink Block Diagram for the Model

Combining MATLAB and Simulink Data-driven Modelling You may use Simulink together with MATLAB in order to specify data and parameters to your Simulink model. You may specify commands in the MATLAB Command Window or as commands in an m-file (Script). This is called data-driven modeling Instead of using values directly we use variables instead - This is more flexible because we can easily change Simulation Parameters without touching the Simulink Model

Example x = ax Instead of using values directly we use variables instead This is more flexible because we can easily change Simulation Parameters without changing the Simulink Model

clear clc Data-driven Modelling MATLAB Script for running the Simulink Simulation: %Set Simulator Settings x0=1; T=5; a=-1/t; t_stop=25; %[s] T_s=t_stop/1000; %[s] options=simset('solver', 'ode5', 'fixedstep', T_s); %Starting Simulation sim('simulink_ex2', t_stop, options); This is the Name for our Simulink Model We get the same results:

Mass-Spring-Damper System In this example we will create a mass-spring-damper model in Simulink and configure and run the simulation from a MATLAB m-file. The differential equation for the system is as follows: x =, (F cx kx) - Where: x - position x - speed x - acceleration Instead of hard-coding the model parameters in the blocks you should refer to them as variables set in an m-file.

The following variables should then be set in the m-file: x_init = 4; %[m]. Initial position. dxdt_init = 0; %[m/s]. Initial Speed. m = 20; %[kg] c = 4; %[N/(m/s)] k = 2; %[N/m] t_step_f = 50; %[s] F_O = 0; %[N] F_1 = 4; %[N]

Force F: Position x and speed x :

Hans-Petter Halvorsen, M.Sc. University College of Southeast Norway www.usn.no E-mail: hans.p.halvorsen@hit.no Blog: http://home.hit.no/~hansha/