- •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
Verification of results of calculation
As it is told above, the system may fix logic mistakes only in the indirect form, but also it happens far from being always. The most inconvenient case for the programmer is when results of calculation are similar to the truth. Therefore, the problem of the proof of correctness of the solution should be put and realized at a development cycle of the program.
Make it with the help of example of the program of calculation of currents in a circuit realized by M – file by name Circuit 3_debug.
At a stage of a development of the program we have carried out check according to 2nd Kirchhoff’s law along the contour that has been not included in system of the equations for a finding of branches currents. The check up is necessary for such electric circuits. Now we shall check up, whether it is sufficient. For this purpose, execute the following actions:
Let's enter a logic mistake into the program. At filling M matrix we shall replace M (1,2) =-1 by M (1,2)= 1. Now the matrix should look as follows:
M = [1 1 -1;
Z1 0 Z3;
0 Z2 -Z3];
Save the program and run it for calculation. Results of calculation are:
I1 =-17.5739-76.7793i
I2=16.5153+79.355i
I3 =-1.0586+2.5757i
error calculation eps=0
I1M=78.7649 phI1 =-102.8923
I2M=81.0554 phI2=78.2435
I3M=2.7848 phI3=112.3428
Thus we see, that curves of currents on the diagram are similar to real ones, and a mistake of calculation eps=0. Hence, it is not enough carried out check for revealing the given logic mistake.
For the electric circuit it is recommended to do check up also according to 1st Kirchhoff’s rule for the unit that has been not included to the system of equations for definition unknowns. We shall organize account of check according to 1st and 2nd Kirchhoff’s rules as follows:
% Check up according to 1-st Kirchhoff’s rule
eps1=I (1,1)-I (2,1)-I (3,1);
% Check up according to 2-nd Kirchhoff’s rule
eps2=E1-E2-Z1*I (1,1)-Z2*I (2,1);
disp ([' error calculation eps1 = ', num2str (eps1)]);
disp ([' error calculation eps2 = ', num2str (eps2)]);
Also shall carry out the appropriate replacements into the program.
Save the program and start it to the account. The results exceeded as follows:
I1 =-17.5739-76.7793i
I2=16.5153+79.355i
I3 =-1.0586+2.5757i
error calculation eps1 =-33.0306-158.71i
error calculation eps2=0
I1M=78.7649 phI1 =-102.8923
I2M=81.0554 phI2=78.2435
I3M=2.7848 phI3=112.3428
Thus, check up according to 1st Kirchhoff’s rule gives an error
eps1 =-33.0306-158.71i. Obviously, as 1st Kirchhoff’s rule do not fulfil so results of calculation are incorrect.
Correct the mistake and start the program again. The following values of errors will be received:
eror calculation eps1=0
error calculation eps2=3.5527e-015+7.1054e-015i
The values of errors testify to correctness of calculation.
3 LAboratory work # 3
TOPIC: Modeling of steady-state electric processes in MATLAB environment. Part 2.
PURPOSE OF THE WORK: Development and debugging of the program of calculation of currents and voltages in the given electrical circuit and proof of correctness of account.