- •Contents
- •1 LAboratory work # 1
- •Mathematical model
- •Stages of a program elaboration
- •Call Desktop matlab
- •Script-files and Function-files
- •Enter of input data by awarding method. Comments
- •Organization of enter of the input data by a dialogue mode
- •Creation of Function-file
- •Graphical output
- •2 LAboratory work # 2
- •Debugging and verification of programs
- •Search of syntactic mistakes
- •Debugging with the help of Editor/Debugger
- •Verification of results of calculation
- •3 LAboratory work # 3
- •The task for fulfillment
- •Individual tasks
- •4 LAboratory work # 4
- •Mathematical model
- •The block-diagram of algorithm of calculation according to mathematical model
- •The task for fulfillment
- •5 LAboratory work # 5
- •The task for fulfillment
- •Individual tasks
- •6 LAboratory work # 6
- •Mathematical model
- •Determination of zero approximation
- •Program of calculation in matlab environment
- •Results of calculation
- •Individual tasks
- •The task for fulfillment
- •7 LAboratory work # 7
- •Mathematical model
- •Program of calculation at matlab environment
- •Results of calculation
- •Individual tasks
- •The task for fulfillment
- •8 LAboratory work # 8
- •Mathematical model
- •Results of calculation
- •Improvement of convergence of the Newton method
- •The task for fulfillment
- •9 LAboratory work # 9
- •Mathematical model
- •The program of calculation in matlab environment
- •Results of calculation
- •The task for fulfillment
- •10 LAboratory work # 10
- •The task for fulfillment
- •Individual tasks
- •LIst of literature
Debugging with the help of Editor/Debugger
One of means of tool search of mistakes is application of the built - in system of editing and debugging of programs by name Editor/Debugger.
Let’s familiarize with Editor/Debugger options with help an example of program Circuit1_debug.
Before the session will be begun, it is expedient to clear Workspace with the help of command Clear and Command Window with the help of command Clc entered in Command Window (it is possible to use Main menu EditClear Workspace and Main menuEditClear Command Window with this purpose).
Start debugger of programs. For this purpose press Main menuDebugRun. After that, pointing out the cursor to any variable or an array in the text of the program, it is possible to look after their numerical (or symbolical) values.
Clear Workspace and Command Window. Stand up the cursor before any operator. Let it be the operator in a line 13
XL=2*pi*f*L2;
Press icon Set/clear breakpoint on panels of tools. The red point from the left of the specified operator designates a point of interruption of the program running. Press DebugRun. The green arrow appeared in the text of the program points out to the operator before that calculations are stopped. In Command Window you will see the invitation
K> >
to enter the further instructions. Before you will make it, bring the cursor to values of the variables calculated before interruption. The system will show these values. However, you cannot view values of variables and arrays after point of interruption, as they are not determined yet.
Press icon Step on panels of tools. The green arrow will be moved for one line downwards. The program has executed one operator and has again stopped. Thus, it is possible to carry out the program step by step, supervising both a sequence of calculations and values of the calculated variables and arrays. Finish up to the end performance of the program, using step-by-step calculation. Observe change and appearance of the new information.
Start the program again (press DebugRun). To execute the program to nearly up after interruption, press button Continue on panel of tools. You will see results of calculations in Command Window.
By means of button Set/clear breakpoint, it is possible to remove the point of interruption shown by cursor. By means of button Clear all breakpoints, it is possible to remove all points of interruption in the program.
To come in the subroutine using step-by-step debugging call M – file by name Circuit 3 from the editor of programs. Save it in the same directory as Circuit 3_debug. Purposely of economy of time, we shall replace operators of dialogue entering by awarding operators (use for this purpose operators of input of M - file Circuit 1).
The program should look as follows:
% THE EXAMPLE OF CALCULATION OF THE SINE WAVE
CURRENT CIRCUIT
% Circuit 3_debug
f=50;
R1=1;
R2=2;
R3=3;
L2=1e-3;
C3=1e-4;
ph1=30;
ph2=60;
XL=2*pi*f*L2;
XC=1 / (2*pi*f*C3);
E1=100/sqrt (2) *exp (ph1*pi/180*i);
E2=200/sqrt (2) *exp (ph2*pi/180*i);
Z1=R1; Z2=R2+i*XL; Z3=R3-i*XC;
M = [1 -1 -1;
Z1 0 Z3;
0 Z2 -Z3];
F = [0; E1; -E2];
I=M\F;
disp ([' I1 = ', num2str (I (1,1))]);
disp ([' I2 = ', num2str (I (2,1))]);
disp ([' I3 = ', num2str (I (3,1))]);
% Check up according to 2-nd Kirchhoff’s rule
eps=E1-E2-Z1*I (1,1)-Z2*I (2,1);
disp ([' error calculation eps = ', num2str (eps)]);
% Calculation modules and arguments (radians) of the calculated currents
I1M=abs (I (1,1));
I2M=abs (I (2,1));
I3M=abs (I (3,1));
phI1=angle (I (1,1));
phI2=angle (I (2,1));
phI3=angle (I (3,1));
disp ([' I1M = ', num2str (I1M), ' phI1 = ', num2str (phI1/pi*180)]);
disp ([' I2M = ', num2str (I2M), ' phI2 = ', num2str (phI2/pi*180)]);
disp ([' I3M = ', num2str (I3M), ' phI3 = ', num2str (phI3/pi*180)]);
% GRAPH
h=0.04/200;
t (1)= 0;
i1 (1) =current (I1M, f, phI1, t (1));
i2 (1) =current (I2M, f, phI2, t (1));
i3 (1) =current (I3M, f, phI3, t (1));
for k=2:201
t (k) =t (k-1) +h;
i1 (k) =current (I1M, f, phI1, t (k));
i2 (k) =current (I2M, f, phI2, t (k));
i3 (k) =current (I3M, f, phI3, t (k));
end
plot (t, i1, t, i2, t, i3);
To investigate operation of the program by a cycle, as a rule, it is enough to do 2 - 3 entries in it. Therefore, replace the top limit of the operator of a cycle as follows
for k=2:5
t (k) =t (k-1) +h;
i1 (k) =current (I1M, f, phI1, t (k));
i2 (k) =current (I2M, f, phI2, t (k));
i3 (k) =current (I3M, f, phI3, t (k));
end
Save the changed program.
Stand up cursor before the operator of definition of a time step of calculation of values of branch current functions.
h=0.04/200;
Also, set up a breakpoint.
For the control of performance of subroutines, take advantage of option Step in on the panel of tools, that enables to look after step-by-step performance of subroutine operators. Execute the program up to the end with the help of this option.
Option Step out allows to leave the subroutine at any stage of its running.
Option Exit Debug Mode realizes an exit from a mode of debugging.
From Main menu Breakpoints menu, it is possible to click additional options of debugging:
Stop If Error – stop of the program in case of a mistake;
Stop If Warning – stop of the program in case of the system warning of a probable mistake;
Stop If NaN Or Inf - stop of a case not numerical or infinite value of calculated value.
Application of those or different ways and options of debugging of programs is determined by the programmer himself according to his experience, qualification, a complexity of a solved problem and individual style of programming.