CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.

Slides:



Advertisements
Similar presentations
Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.
Advertisements

Why care about debugging? How many of you have written a program that worked perfectly the first time? No one (including me!) writes a program that works.
Debugging in Matlab C. Reed 4/5/11. Bugs Debugging is a natural part of programming: Three standard types of errors: –Syntax errors: you simply have typed.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 19P. 1Winter Quarter MATLAB: Script and.
MT311 Tutorial Li Tak Sing( 李德成 ). Uploading your work You need to upload your work for tutorials and assignments at the following site:
Lecture Roger Sutton CO331 Visual programming 15: Debugging 1.
General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009.
17 March, 2000 CS1001 Lecture 2 Programming and problem solving Software engineering practices.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
A Brief Introduction to MATLAB Shibaji Shome and Rob MacLeod CVRTI University of Utah.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
Finding and Debugging Errors
Programming Fundamentals (750113) Ch1. Problem Solving
DEBUGGERS For CS302 Data Structures Course Slides prepared by TALHA OZ (most of the text is from
Functions UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative Commons.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
Python Mini-Course University of Oklahoma Department of Psychology Day 1 – Lesson 2 Fundamentals of Programming Languages 4/5/09 Python Mini-Course: Day.
Lecture 1: Introduction Lecture series based on the text: Essential MATLAB for Engineers and Scientists By Hahn & Valentine
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
BRIAN D. HAHN AND DANIEL T. VALENTINE THIRD EDITION Essential MATLAB® for Engineers and Scientists.
CHAPTER 5: CONTROL STRUCTURES II INSTRUCTOR: MOHAMMAD MOJADDAM.
DEBUGGING CHAPTER Topics  Getting Started with Debugging  Types of Bugs –Compile-Time Bugs –Bugs Attaching Scripts –Runtime Errors  Stepping.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5.
Debugging UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative Commons.
CPS120 Introduction to Computer Science Iteration (Looping)
Python From the book “Think Python”
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
IXA 1234 : C++ PROGRAMMING CHAPTER 1. PROGRAMMING LANGUAGE Programming language is a computer program that can solve certain problem / task Keyword: Computer.
Chapter 5: Control Structures II (Repetition). Objectives In this chapter, you will: – Learn about repetition (looping) control structures – Learn how.
COMP 116: Introduction to Scientific Programming Lecture 11: Functions.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Script Files UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
Chapter Six Introduction to Shell Script Programming.
Software Engineering CS103 February 13, How Do You Solve Big Problems? Thousands of programmers Thousands of programmers Months or years of coding.
CPS120 Introduction to Computer Science Iteration (Looping)
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 1 Monday 29 Sept 2014 EGR 115 Introduction to Computing for Engineers.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 6: Debugging in MATLAB Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers.
Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal.
CMSC 2021 Software Development. CMSC 2022 Software Development Life Cycle Five phases: –Analysis –Design –Implementation –Testing –Maintenance.
Chapter 6 Programming l Problem solving l Debugging.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
Chapter 7 What’s Wrong with It? (Syntax and Logic Errors) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Introduction to Computing Systems and Programming Programming.
COMPUTER PROGRAMMING I SUMMER Understand Different Types of Programming Errors.
Debugging M-Files Steve Gu Feb 08, Outline What’s Debugging? Types of Errors Finding Errors Debugging Example Using Debugging Features.
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
Creating a script create new blank document. Editor options Docking and undocking tabs.
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
EGR 115 Introduction to Computing for Engineers
ME 142 Engineering Computation I
Lecture 1 Introduction Richard Gesick.
Key Ideas from day 1 slides
Testing and Debugging.
Scripts & Functions Scripts and functions are contained in .m-files
Chapter 4 – Control Structures Part 1
Lecture 1: Introduction
Problem Solving Techniques
Programming Problem solving Debugging
Programming Fundamentals (750113) Ch1. Problem Solving
Programming Fundamentals (750113) Ch1. Problem Solving
Debuggers and Debugging
Programming Fundamentals (750113) Ch1. Problem Solving
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
ICT Gaming Lesson 2.
Programming Fundamentals (750113) Ch1. Problem Solving
Chapter 1 c++ structure C++ Input / Output
Chapter 15 Debugging.
Chapter 15 Debugging.
Presentation transcript:

CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING

Software Engineering Goals: Understand difficulties in solving large programming problems Develop effective methods for writing large programs How do we define a good program? What is a bug? Why is SW Engineering important?

Top-Down Design Should we start solving a problem by coding the solution immediately? CASE: Computer Aided SW Engineering Decomposition: divide problem to sub problems Stepwise refinement: repeated application of decomposition

Top-Down Design 1. State the problem 2. Define the inputs and outputs 3. Design the algorithm a) Decompose into subproblems b) Perform stepwise refinement 4. Convert the algorithm into a Matlab program 5. Test the program Which step is the most difficult and why? What is an iterative process?

Script Files Script files text files (created with a text editor) contain many lines of MATLAB expressions and assignments. You can execute all of the lines of the file (sequentially) by typing the filename at the MATLAB prompt. If filename is computetraj.m, then >> computetraj causes the instructions (ie., the MATLAB commands) in the file to be run.

Debugging your programs Is it possible to have errors in your program? Three different types of errors are Syntax errors: you simply have typed an illegal expression, independent of the values of the variables in the expression. Run-time errors: logic errors that result in an illegal expression for specific values of the data (harder to fix). Logic errors that result in the program executing completely, but the answer that they return is incorrect (hardest to fix).

Finding run-time errors (bugs) The most primitive way to debug a program is to Work out (by “hand”) Remove the trailing semicolons ; Call your program, and compare the printouts (your program) to your hand-calculations

Finding run-time errors (bugs) A better (but ultimately the same) way is to Work out (by “hand”) Insert the command keyboard at some point in your program. This is called “setting a breakpoint” Run the program When execution gets to the keyboard line program execution is temporarily stopped the Command window appears, the prompt is K>> control it at the keyboard (ie., you can type) Type expressions at the K>> prompt You are a detective at this point. Type K>> return (resume execution) or K>> dbquit (exit)

Single-line stepping through an m-file Use dbstep to step through an M-file a line-at-a-time To execute the next line of code, type K>> dbstep To execute the next 6 lines of code, type K>> dbstep 6 To execute code until another m-file function is called, and then to “stop inside” that function at its first line, type K>> dbstep in To execute code until the m-file function exits, and then to stop inside the m-file function that called it, type K>> dbstep out After any of these, the “instruction pointer” moves to the next line of code which has not executed.

Stopping in an M-file Use dbstop to stop in an M-file at a certain line if a condition is true. To stop in loancalc at line 11 if the variable G is less than 1 K>> dbstop in loancalc at 11 if G<1 This sets a conditional breakpoint.

Clearing breakpoints All breakpoints can be cleared with the command >> dbclear all You can also selectively clear breakpoints that were created with dbstop. See >> help dbstop >> help dbclear for more information.

Using dbup and dbdown Normally at a breakpoint execution is temporarily stopped the K>> prompt appears in the command window the variables in the function’s workspace can be examined. The command dbup changes the scope of visible variables to the caller’s workspace. K>> % examine variables in function’s workspace K>> dbup K>> % examine variables in caller’s workspace K>> dbdown K>> % examine variables in function’s workspace

Seeing all of the function instances Use dbstack to see the list of all function instances that are running. The top line gives the function instance where the dbstack command occurred. The (n+1)’th line is the function instance of the function which called the function instance listed on the n’th line.

Profiling your code When running a program, Matlab can keep track of How many times a single line is executed How many times a function is called How much total time is spent executing a specific line of code How much time is spent running a specific function Why is this information useful? >> profile on >> myprogram >> profile report

QUESTIONS??

Resources “Introduction to Programming with Matlab”, J. Michael Fitzpatrick and John D. Crocetti Lecture slides E77, Andy Packard,