VNVe - MATLAB/Simulink simple help
- Download Simulink schemes: Example1, Example2, Example3. Save this files to your working directory (with mdl extensions!!!).
- Execute Matlab (shortcut on your desktop or on Q:/MATLAB for Windows).
- Set appropriate directory in Matlab (to your files) using 'cd' command or clicking on active folder shortcut.
- Executing e.g. 'open Example1' open simulink schema. Exemplary solution of the example1 (exponential function) from the previous laboratory is prepared.
- Playing with the examples, try to learn some basics of simulink.
- Checking 'View/Library Browser' you open window with supported Simulink elements. There are many such elements but usually only those from 'Commonly Used Blocks' are needed.
- To display a progress use 'scope' block.
- Simulink is capable of creating a subblock from a part of a block. This subblock can be opened by doubleclick. The blocks of 'Numerical solution' and 'Analytic solution' are already implemented in Example1. Your task is to implement the blocks in Example2 and Example3.
- Doubleclick can be used to open 'block properties setting window' (i.e. initial conditions of integrators, sum input types, etc.) as well.
- In 'Simulation/Configuration Parameters...' menu, simulation parameters can be set, e.g. simulation interval length, integration step, integration method, etc.
- The simulation is starting choosing the item 'Simulation/Start' in menu. Doubleclicking the oscilloscope ('scope' block) displays individual progresses. Autoscale adjusts displayed graph.
- Oscilloscope error displays error of both solutions (the difference between the numerical and analytical solution). If your circuit is correctly implemented, this error should be in order of 10^-10.
- Since oscilloscope does not support exporting into png files (pictures files), oscilloscope variables e.g. y_num, error, ... are set to save measured data into matlab. This is done inside of an oscilloscope through 'Parameters' menu in 'Data History' section (check 'Save data to workspace' and set 'Array' format). Set the same for all oscilloscopes.
- To display measured progresses execute 'plot(y_num(:, 1), y_num(:, 2))' command in matlab's window (Command window). Created picture can be then exported into png (or other graphic files).
- Display all progresses of the system of differential equations (use 'Bus Creator' block in Simulink). Than plot command for more graphs in figure should be e.g. for 3 variables 'plot(y_num(:, 1), y_num(:, 2), y_num(:, 1), y_num(:, 3), y_num(:, 1), y_num(:, 4))' Insert final progresses with matlab script (you can use m file script for plotting figures or just writing commands to Command window) displaying them into one figure (legend is mandatory) into protocol.
- Use measured y_num progress, compared with y_anal and check the error in your protocol (for all graphs use Autoscale to see the progress, otherwise it is not seen).
- Compare it with progresses computed in the previous lab (using TKSL software).
Useful commands (MATLAB Command window):
- clear all - erase all defined variables
- close all - close all windows created by 'figure' command
- help command - displays help for command
- doc command - display interactive help for command
- figure - creates new window for drawing functions/progresses and sets it as active
- plot - displays progress into the active window
- subplot - divides windows (figure) into sub-regions (subplots)
- hold on - normally if you call plot, active window is redisplayed. Hold on command provide that new function graph in active figure is ploted (no deleting previous graphs).
- hold off - turn off hold on
- title - set caption
- legend - set legend (necessary to call after 'plot' command)
- xlabel - add label for x axis
- ylabel - add label for y axis
- grid on - displaying grid in the graph
- gcf - get actual window ID
- saveas(ID, file_name, method) - save window with ID into a file. Method can be for example 'png' for figure or 'psc2' for vector figure in eps format. For example saveas(gcf, 'prubeh.png', 'png') creates a file from actually displayed graph.
- ...