Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

SPRING 2017 DSTR-ENGR112 HW02 The following tasks are individual assignments, to

ID: 3870838 • Letter: S

Question

SPRING 2017 DSTR-ENGR112 HW02

The following tasks are individual assignments, to be submitted online before 11:59PM Sep 11.

The purpose of this assignment is to review the basic capabilities and properties of Matlab and to prepare for writing code in EmbeddedC. You should:

Plan your solutions (e.g., HW02-1 and HW02-3)
o Document your plan for each solution using a flowchart or pseudo-code.
o Submit each plan as a separate file (HW02-1.io, or HW02-1.ppt, or HW02-1.txt,

etc.).
Document each Matlab function (e.g., HW02-2 and HW02-4) before your enter it and as you debug it –

o Use Matlab comments as needed.
o The comments should explain the meaning or usage of variables and major

sections of code. Line-by-line comments may not be completely necessary.

o Submit each Matlab function as a separate file (HW02-2.m, etc.).

Document the proper operation of each Matlab function (e.g., HW02-2 and HW02-4) after you are have verified it is working as expected –

o Capture a sample of the actual output of each Matlab function (displayed in the Matlab command window).

o Submit a sample of the actual output of each Matlab function as a separate file (HW02-2test.txt or HW02-2test.pdf, etc.).

HW02-1

Develop an algorithm which generates an infinite loop and turns ON (i.e., True, Hi, or Logic 1) a Boolean Variable, LED1, once every fourth iteration. Write a flowchart Matlab script which generates an infinite loop in Matlab.

Document this algorithm using a flowchart or pseudo-code.
o For a flowchart, use an online tool such as “draw.io” (or powerpoint). Hand-

written drawings (sketches) are permitted for In-Class Activities (for

time/expediency) but ARE NOT acceptable for this HW assignment.
o For pseudo-code, use a simple text file and standard pseudo-code protocol.

Use the variable names specified and document (explain) any additional variables.

Submit this plan as a separate file (HW02-1.io, or HW02-1.ppt, or HW02-1.txt, etc.).

SPRING 2017 DSTR-ENGR112 HW02

HW02-2
Write a Matlab function which implements the algorithm developed in HW02-1.

Document this function with Matlab comments. This will help you when you implement this algorithm in other programming languages, such as EmbeddedC.

Submit this Matlab function as a separate file (HW02-2.m)

Capture the 5-10 lines of actual output of this function to demonstrate its correct

operation. Save this output as a text file or pdf file (converted from an image).

Submit this output as a separate file (HW02-2.txt or HW02-2.pdf).

HW02-3

Develop an algorithm which generates an infinite loop and turns ON (i.e., True, Hi, or Logic 1) a Boolean Variable, LED1, for three iterations, then OFF for five iterations. Here is an abbreviated trace table of the expected output:

Document this algorithm using a flowchart or pseudo-code (as for HW02-1).

Use the variable names specified and document (explain) any additional variables.

Submit this plan as a separate file (HW02-3.io, or HW02-3.ppt, or HW02-3.txt, etc.).

HW02-4
Write a Matlab function which implements the algorithm developed in HW02-3.

Document this function with Matlab comments. This will help you when you implement this algorithm in other programming languages, such as EmbeddedC.

Submit this Matlab function as a separate file (HW02-4.m)

Capture the 10-15 lines of actual output of this function to demonstrate its correct

operation. Save this output as a text file or pdf file (converted from an image).

Submit this output as a separate file (HW02-4.txt or HW02-4.pdf).

Explanation / Answer

Unlike fields in C++ or the Java language, you can use MATLAB properties to define a public interface separate from the implementation of data storage. You can provide public access to properties because you can define set and get access methods that execute automatically when assigning or querying property values. For example, the following statement:

myobj.Material = 'plastic';

assigns the char vector plastic to the Materialproperty of myobj. Before making the actual assignment, myobj executes a method called set.Material (assuming the class of myobj defines this method), which can perform any necessary operations. See Property Access Methods for more information on property access methods.

You can also control access to properties by setting attributes, which enable public, protected , or private access. See Property Attributes for a full list of property attributes.

No Implicit Parameters

In some languages, one object parameter to a method is always implicit. In MATLAB, objects are explicit parameters to the methods that act on them.

Dispatching

In MATLAB classes, method dispatching is not based on method signature, as it is in C++ and Java code. When the argument list contains objects of equal precedence, MATLAB uses the left-most object to select the method to call.

However, if the class of an argument is superior to the class of the other arguments, MATLAB dispatches to the method of the superior argument, regardless of its position within the argument list.