Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


Engr 3: Intro to Programming

Summer 2021

Homework 6


Please remember to include comments in your programs.


1. (15 points total)

(a) (5 points) For the DC circuit shown here, Kirchhoff’s Rules and Ohm’s Law tell us the following relationships between the currents the resistances  and the voltage provided by the battery:

Write a function find_current.m which takes as inputs the values for and  and returns as output a column vector containing the values of the currents  in that order.

(b) (10 points) Suppose  = 100 Ohms,  = 200 Ohms, and = 9 Volts. Plot  and versus using the values = 0.1, 0.2, 0.3, · · · , 10000 Ohms, in two different ways.

First, in figure(1), plot this using linear axes; this is what you get from the plot command. All three quantities and should be shown in this one figure.

Second, in figure(2), plot this with a linear vertical axis and a logarithmic horizontal axis; this is what you get from the semilogx command, which uses the same syntax as the plot command. Again, all three quantities and should be shown in this one figure.

Your figures must have labelled axes (including units), and use the legend command to specify which curve is which.

Please submit the files find_current.m and plot_current.m.


2. (20 points)

The US Postal Service handles over 150,000,000,000 pieces of mail every year. With this sort of volume, it is impractical if not impossible for every destination address to be read and analyzed by a person. The natural solution? Computerized handwriting recognition software. In this problem, you will be writing a program which will automatically identify a series of five numbers, such as would be found in a zip code.

        It is necessary for our system to know what different numbers look like. This is done by normalizing and analyzing a set of “test” images. Each number is made approxi-mately the same size and stored in a 28x28 matrix, with each element corresponding to a grayscale value between 0 and 1 (0=black, 1=white). Then all the matrices associated with one number are analyzed to determine what an average handwritten number looks like. Fortunately, this has already been done so you can start with a set of reference numbers to compare with, which are shown here:

Note that these are a little fuzzy around the edges, as all handwritten numbers look a bit different. The goal is that one of these reference numbers is more similar to the number we are trying to identify than the others, and we will then assign the handwritten number the value of the most similar reference number.

        Start by downloading the file input.mat from Gauchospace. Contained in this file you will find an array of cells called digit_avg, which stores the reference numbers, and the series of numbers you are to decipher, sample. Accessing a reference numbers is as easy as calling the number you want with curly brackets. For example digit_avg{1} returns the reference matrix for the number one, digit_avg{2} returns the matrix for the number two, and so on. The exception is zero, which is stored as digit_avg{10}. You can plot a single reference digit with the following command, here for “3”:

imshow(digit_avg{3})

If you want this to be bigger, use

imshow(digit_avg{3},’InitialMagnification’,400)

        The numbers to be identified, in sample are:

Recall that each number is a 28x28 matrix, so the first 28 columns are the first number, the next 28 columns are the second number and so on.

        First, write a function called digit_compare.m which takes as input two 28 × 28 matrices, and returns the sum of the squares of the differences between the corresponding elements. For example, for the matrices d and D, it should calculate

This function can be used to give a scalar measurement of how similar two images of numbers are to each other, with a smaller result meaning that they are more similar. For example, compare

digit_compare(sample(:,1:28),digit_avg{1})

to

digit_compare(sample(:,1:28),digit_avg{2})

        Next, write a program called handwriting_id.m which successively considers each of the five numbers in sample from left to right, comparing each to the 10 possible reference numbers in digit_avg to determine which is most similar - here you’ll want to make calls to digit_compare.m. Your program should output each identified number in sample to the command window.

For this problem, please submit digit_compare.m and handwriting_id.m.