Presentation is loading. Please wait.

Presentation is loading. Please wait.

EGR 115 Introduction to Computing for Engineers MATLAB Basics 6: Debugging in MATLAB Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers.

Similar presentations


Presentation on theme: "EGR 115 Introduction to Computing for Engineers MATLAB Basics 6: Debugging in MATLAB Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers."— Presentation transcript:

1 EGR 115 Introduction to Computing for Engineers MATLAB Basics 6: Debugging in MATLAB Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers

2 Lecture Outline Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers Debugging in MATLAB Symbolic calculations in MATLAB Publishing a file in MATLAB Slide 2 of 13

3 MATLAB basics Debugging in MATLAB Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers Most human beings occasionally make errors Program errors are often referred to as “bugs” Debugging refers to the process of eradicating “bugs” There are three general classes of programming errors Slide 3 of 13

4 MATLAB basics Debugging in MATLAB – Syntax Errors Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers Types of programming errors  Syntax Error – What students tend to think of when you mention bugs. Found (& reported) by command window or compiler. Frequently typos!!  Examples: >> Cos(pi)  The name of the MATAB function for Cosine is “cos(…)” NOT “Cos(…)” o A(1)) = 5; Slide 4 of 13

5 MATLAB basics Debugging in MATLAB – Syntax Errors Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers  Syntax errors can typically be resolved by carefully reviewing the error message o Sometimes the interpreter will make suggestions on how to fix the problem!! >> A = 1 + 3 + o The response is not always precise Slide 5 of 13

6 MATLAB basics Debugging in MATLAB – Run-time Errors Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers  Run-time Error – Error which is reported when the program is executed. Divide by zero, or multiply by ‘string’, … o Arithmetic type Run-Time Error: >> log10(0) o Indexing type Run-Time Error: >> a = [ 1 2 3 ]; >> b = a(4) Slide 6 of 13

7 MATLAB basics Debugging in MATLAB – Run-time Errors Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers o Assignment type Run-Time Error: >> a = [ 1 2 3 ]; >> b = ones(3, 1); >> c = a + b;  “a” is a 1x3 row vector and “b” is a 3x1 column vector, hence, they are not compatible under addition!! Slide 7 of 13

8 MATLAB basics Debugging in MATLAB – Logical Errors Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers  Logical Error – Hardest error to find, not reported, program runs without reported error, but produces erroneous results. o We wish to test if the class should be over:  Check to see if the time is greater or equal to 4 pm. >> Time = clock;% Obtain current year, month, date, hr, min, sec >> if (Time(4) <= 4 ) % Check to see if after 4pm >> disp('Class should be over'); % If after 4pm display the statement >> end We made another logical error!! The hour variable is in 24 hr format => 4pm = 16 We made another logical error!! The hour variable is in 24 hr format => 4pm = 16 We made a logical error!! Should be >= not <= !!! We made a logical error!! Should be >= not <= !!! Slide 8 of 13

9 MATLAB basics Debugging in MATLAB Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers MATLAB Debugger  Breakpoints o Allows the controlled step-by-step execution of code  Examining contents of variables  Escaping a “run-away” program o CTRL-C Use example of “Hwk1_Soln.m” Slide 9 of 13

10 MATLAB basics Symbolic Calculations in MATLAB Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers MATLAB can perform symbolic calculations  The Symbolic toolbox >> syms t >> y = sin(t) >> diff(y, t) Define “t” as a symbolic variable Slide 10 of 13

11 MATLAB basics Publishing a file in MATLAB Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers MATLAB can “publish” the results of executing a *.m file  Will include plots and results of calculations Slide 11 of 13

12 MATLAB basics Publishing a file in MATLAB Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers  Set the “Output file format” to “doc” before publishing o Input commands will not be processed  Comment “input(…)” related lines or hardcode the input Use example of “Hwk2_Soln.m” Slide 12 of 13

13 Next Lecture Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers 2D Plotting  Additional features Slide 13 of 13


Download ppt "EGR 115 Introduction to Computing for Engineers MATLAB Basics 6: Debugging in MATLAB Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers."

Similar presentations


Ads by Google