Sei sulla pagina 1di 6

NAME: ___________________________________________

CDS-130/005 SPRING 2015: HOMEWORK 2


ASSIGNED February 4 2015, DUE February 11 2015 AT THE END OF CLASS
REMEMBER TO SHOW ALL WORK FOR FULL CREDIT!
BINARY NUMBERS MULTIPLICATION AND DIVISION EXERCISES
Exercise 1 (1 pt): Calculate 11101101112 divided by 6410 (without using a calculator), and
represent the result in floating point binary.

Exercise 2 (1 pt): Calculate 10000101012 multiplied by 3210 (without using a calculator), and
represent the result in integer binary.

Exercise 3 (1 pt): Calculate 110101112 divided by 51210 (without using a calculator), and
represent the result in integer binary.

Exercise 4 (1 pt): Calculate 1011010.10010012 multiplied by 51210 (without using a calculator),


and represent the result in integer binary.

Exercise 5 (1 pt): Multiply the following binary numbers, and express the product in binary:
10111010 1101

Exercise 6 (1 pt): Multiply the following binary numbers, and express the product in binary:
110101 11011

Exercise 7 (1 pt): Multiply the following binary numbers, and express the product in binary:
1110010111 10000000000

Exercise 8 (1 pt): Perform the following BINARY ADDITION and represent the result in integer
binary. (HINT: Do you really want to go through the unbelievable pain and agony of adding a
number to itself sixteen times? OMG!!! Imagine all the carries! Wait . . . hold on a moment . . .
hey, its the same number, repeated sixteen times! . . . ) (again, without using a calculator)
11111111
+11111111
+11111111
+11111111
+11111111
+11111111
+11111111
+11111111
+11111111
+11111111
+11111111
+11111111
+11111111
+11111111
+11111111
+11111111

I call 210, or 102410, the MAGIC NUMBER. I call it that because by memorizing the base ten
value for 210, youll be able to instantly recall it when needed. Furthermore, youll then be
capable of rapidly calculating the base ten values of other, nearby powers of 2with ease! For
example, 211 is just two times 210. So 211 equals 204810. Similarly, 212 is just two times 211. So 212
equals 409610. Etc.
Exercise 9 (1 pt): How many different combinations of 1 and 0 are possible using 13 bits?
(express your answer in base ten) (Were you thinking about using a calculator? Dont.)

Exercise 10 (1 pt total): What is the largest possible positive, base 10 integer that can be
represented using 13 bits?
(a) (0.5 pt) Write the answer in base ten; and then
(b) (0.5 pt) Write the answer in binary.

Exercise 11 (1 pt): What is the minimum number of bits required to write the base ten number
3,357 in binary? (NOTE: In binary numbers, individual 1s and 0s are called bits. And so, the
binary number 101101 is comprised of six bits, or, is referred to as a six bit binary number)

MATLAB SYNTAX EXERCISES


NOTE: While its possible to simply copy and paste the following Matlab codes directly into
Matlab, run them, and produce correct answers, DO NOT DO THAT. Why, you ask? Because
youll encounter problems on future quizzes and exams that are very similar to these exercises.
Since you wont be permitted to use Matlab on quizzes and exams, you may suddenly find
yourself unable to cope with the quiz and exam problems if you havent developed the ability
to do these exercises by hand. So its much better to get the practice you need now (when you
have time to spare), rather than try to figure it out later, when time is a very precious
commodity!
Exercise 12 (1 pt):
Youre given the following two Matlab programs. Each program is
independent and no other statements precede either program:
PROGRAM A:

PROGRAM B:
a = 1;
b = a - 3;
a
b

b = a - 3;
a = 1;
a
b

When PROGRAM A is executed in Matlab (statements execute in order, from top to bottom),
values for a and b are printed to the command console, but when PROGRAM B is executed
(again, from top to bottom) in Matlab, an error results. Explain why.

Exercise 13 (1 pt):
What output results when the following Matlab program executes (in
order, from top to bottom)?
a
b
c
d

=
=
=
=

1
3;
2*a - 3*b;
c^2

Exercise 14 (1 pt):
What output results when the following Matlab program executes (in
order, from top to bottom)? (HINT: pi is an INTRINSIC I.E., BUILT-IN MATLAB CONSTANT)
a
b
c
d

=
=
=
=

cos(pi);
sin(pi/2);
2*a*b - 3;
a - b + c*c*c

Exercise 15 (2 pts):
What output results when the following Matlab program executes (in
order, from top to bottom)? (HINT: Remember the ORDER OF OPERATIONS)
a
a
b
c
d

=
=
=
=
=

(1 + 2 - 3*4 - 1)/5
((a + a)*a)/a
-1*a/4
b^3 - 4
a - b + c*c*c

Exercise 16 (2 pts):
What output results when the following Matlab program executes (in
order, from top to bottom)?
a = 2^3;
b = cos(0);
c = abs(sqrt(16));
d = a*c - b*c;
d1 = a;
d2 = d;
d3 = d1 - d2 + d*2*(d1/c)

MATLAB PROGRAMMING EXERCISE


Exercise 17 (4 pts): YOU MUST WRITE MATLAB CODE AND THEN EXECUTE YOUR CODE TO
PRODUCE OUTPUT THAT SOLVES THE FOLLOWING PROBLEM. GOOD REFERENCES TO HELP
YOU WITH THIS EXERCISE ARE Car Loan Example and Simple Pendulum Example,
COVERED IN CLASS (CHAPTER 3 PART II OF MATLAB PRESENTATION). READ THESE EXAMPLES,
EXECUTE THE MATLAB PROGRAMS, AND OBSERVE HOW THE OUTPUTS FROM THOSE MATLAB
CODES SOLVE THE ASSOCIATED PROBLEMS. DOING SO WILL DEMONSTRATE FOR YOU HOW
TO SOLVE THE FOLLOWING PROBLEM . . .
INTRODUCTION:
The height above the Earths surface (Y) of a small object falling under the influence of gravity,
without air resistance, depends upon the elapsed time of the fall (t), the acceleration due to
gravity (g; assumed constant), the objects initial velocity (v) and its initial height above the
Earths surface (h). The equation used to calculate Y is as follows:
1
= 2 + +
2

Where: Y is a variable assigned the value of the height (in meters) of the object above the
Earths surface; t is a variable assigned the value of the elapsed time (in seconds); g is a variable
assigned the value of the Earths constant acceleration due to gravity (in meters per second2), v
is a variable assigned the value of the objects initial velocity (in meters per second), and h is a
variable assigned the objects initial height above the Earths surface (in meters).
PROBLEM:
A small object is released at an initial height above the Earths surface of h = 935.0 meters. Its
initial velocity is v = -18.0 meters per second, and the Earths acceleration due to gravity is g =
9.81 meters per second2. What is the height of this object above the Earths surface after one
second has elapsed? After three seconds have elapsed? After eight seconds have elapsed?
How many seconds will elapse before the object hits the surface of the Earth? (NOTE: The
object hits the surface of the Earth when Y = 0.0 meters. You dont have to obtain Y = 0.0
exactly, just get close enough, where close enough means within 2.0 meters. In other words,
keep varying t, running your program each time you do, until you obtain a final value for Y that
is between 2.0 meters and -2.0 meters. The corresponding value of t that produced this final
value for Y, is the answer youre looking for.)
NOTE:
You will need to translate the above equation into CORRECT MATLAB SYNTAX so that your
program will run. Meaning: if you write vt , hoping that Matlab will figure out that you really
meant to write v*t , well, youre asking too much because Matlab aint that smart! And so
you will get an error if you do this.

Potrebbero piacerti anche