CS101

Lab activity #1 Solution Sheet

Only 1st ~ 54th problems are counted for points.
(55th, 56th problems are not counted!)

# of correct answers : points
51-54 : 9
45-50 : 8
39-44 : 7
33-38 : 6
27-32 : 5
21-26 : 4
15-20 : 3
09-14 : 2
03-08 : 1
00-02 : 0


No deductions for writing an answer as 1 or 1.0 or 1.00 or 1.0e0 , ... )
No deductions for writing an answer as [ 1 2 3] as 1 2 3 and
    [1;2;3] as 
1
2
3
No deduction for omitting ans =  or x =

Part 2 Matlab constants

Fill in the following blanks with the correct answers. If the answer gives a Matlab error message, don't write down the entire message, just fill in the blanks with the word ERROR.

1. 
>>  1 / 3
ans =

________0.33333333333333___if they used format long___or ____3.333333333333333e-001__if they used format long e___ (accept 0.3... with any number of 3's)

2.
>> 1\ 3
ans =

_______3________________

3.
>>  2^5
ans =

________32_______________ (exponentiation 2 raised to the fifth power)

4.
>> 2.0e0-3.0e1* 5.0e1
ans =


_______________-1.498e3____ OR -1498______________(operator precedence)

5.
>> (2.0e0-3.0e1)*5.0e1
ans =

________-1.4e3 OR -1400_______________( parenthesis can change operator precedence)

6.
>>  Inf  +  1
ans =

________Inf__________Some students typed Inf   +1 which would generate an ERROR so accept this answer.______

7.
>> Inf  -  1
ans =

________Inf__________Some students typed Inf   -1 which would generate an ERROR so accept this answer.______

8.
>> 1/Inf
ans =

_______0_______________

9.
>> Inf/Inf
ans =

_______NaN_______________

10.
>> 0 * Inf
ans =

_______NaN_______________

11.
>> (-1) * Inf
ans =

_________-Inf_____________

12.
>> Inf - Inf
ans =

________NaN______________

13.
>>1 / 0
ans =

_______Inf_______________

14.
>> -1 / 0
ans =

_______-Inf_______________


15.
>> i * i
ans =
__________-1____________  (Check your high school algebra book on the imaginary number i .)


16.
>> format short
>> 1+ 2*i
ans =

____1+2i__________________ (The general form of a complex number is "a+bi" where a and b are real numbers.)

17.
>> 1+2i
ans =

______1+2i________________ (no * is needed)

18.

>> ( 1+ 2i) + ( 3+ 4i)
ans =

______4 + 6i_________________ (addition of complex numbers)

19.
>> (1+ 2i ) * ( 3+ 4i)
ans =

______-5 + 10i_________________ (multiplication of complex numbers)

20.

>> (1+2i) / ( 3 + 4i)
ans =

_______.44 + .08i________________ (division of complex numbers)

Part 3 Matlab lists (row vectors and column vectors)

21.
>> [ 1  2  3] '    (that's two apostrophes not one double-quote character on your keyboard)
ans =


            1
            2
            3

____________________

NOTE: Accept "Error" as a valid answer because this question had a typo.

22.
>> [ 1;2 ; 3] + [ 4; 5 ; 6]
ans =

5
7
9
_______________________

23.
>> [ 1; 2; 3] + [ 1 2 3]
ans =

___ERROR____________________  ( the two vectors are of the same length but not the same size)

24.

>> [  [ 1 ; 2 ; 3] , [ 1 2 3]' ] (yeah this is really a table type problem)

ans =

1      1
2      2
3      3
______________________

25.
>> x = -1 : 3

x =
___-1  0  1  2  3___________

26.

>> x = 1 : -3 : 7

x =
___  [  ]_____or "the empty matrix"___________

Part 4 Matlab variables

27.
>>  x = [ 1 1 1]
>>  x = x + [1 1 1]

x =
___2   2    2______________

28. 
>> x
x =

_____2   2   2____________  ( didn't we assign [ 1 1 1] to x???)

29.

>> y = [ x , 2 3 4]
y =


_____2   2   2   2   3   4_____

 

Part 5 Matlab functions

30.
>> x = linspace(-1, 1, 4)
x =

____-1  -.3333  .3333  1_________________ ( equally spaced vector starting at -1 ending at 1 with 4 values)

or   -1  -1/3  1/3 1

31.
>> x = linspace(0, 5, 1000);  (don't forget this semi-colon, it means suppress out to screen)
>> min(x)
ans =

______0________________ (of course!)

32.
>> max(x)
ans =

_______5_______________( same x as above)

33.
>> x = [ 1 3 5]
>> sum(x)
ans =

________9____________

34.
>> sum([1 ; 3 ; 5])

ans =
_________9___________

35.
>> z = [ 1 2 3; 4 5 6]
>> sum(z)
ans =
5      7      9
____________________ (sums values in columns for a table; nearly all Matlab functions work this way on tables)

 36.
>>  x = [ 1  3  6 12]
>> diff(x)
ans =

____2  3  6_________________ (diff(x) consecutive  differences of values in x)

37.
>>  x = [ 1 2 3]
>> mean([ 1 2 3])
ans =


_______2______________(arithmetic average = (1+2+3)/3)

38.
>> x = [ 1  2  3 ]
>> median(x)
ans =

_________2_____________( median(x) = as many values above as are below)

39.
>> x = [ 1 2 3 4]
>> median(x)
ans =

________2.5_____________

40.
>> x = [ 1 2 3 4]
>> cumsum(x)
ans =

____1  3  6  10_________________ (cumlative sum)

41.
>> sqrt(-1)
ans =
______i________________
or
0 + i

42.
>> abs( 1+ 2i)
ans =

_______2.2361_______________  ( abs( a+bi) = sqrt(a*a +b*b) )

 

Part 6 Matlab Editor

You should read the instructions for Part 6 and create a Matlab script file before you attempt the followings:

43. Before we run the script file, in the Matlab environment,  enter the who command that lists all your variables,

>> who

List the variables:

___ans   x    y   z _(any answer accepted )______________________________________________________

 

44. Now type the following,

>>clear
>>who

List the variables:

____________no variables______or empty_______________________________________________

45. Next type,

>> r = 1;
>>who

List the variables:

___________r___________(but not  ans)_________________________________________________

>>r

46.
What is the value of r? ___1______

Use the "what" system command to make sure that you have correctly saved your lastname.m file.

>> what (this lists the .m and .mat files in your directory)

If you don't see the "lastname.m" file ask your TA for help before you proceed.


47. Run the script.

>> lastname

Write what is displayed on your screen:

x =
        1      2      3
y =
       0.8415   0.9093   0.1411

________________________________________________________________

48. Type

>>r

What is the value of r? ___4______

 

49.  So, can running a script alter the value of a workspace variable?  Yes


50. Again, type

>> who

List the variables in your workspace:

_________ans     r    x    y____________________________________________

Part 7 Symbolics in Matlab

51. Compute the derivative of t3 with respect to t,

>> syms t
Fill in the blank with Matlab code to call the diff function to compute the second derivative of  t3. You must use the diff function.

>> solution = ____diff( t^3,t,2)_or diff(t.^3,t,2) or  diff(t^3,2) or diff(t.^3,2) (solution should give 6t )

52. Write the result of executing the following code,
>>  syms y
>> limit( sin(y)/y , y , 0)


__________1_________________

53. Write the result of executing the following code,
>> syms z
>> diff( sin(z), z , 4)


_______sin(z)____________________

Part 8 Course Website

54. Find in the course syllabus: Find the grade range(in points for an A- grade for CS101)

__________625-649______________

55. Click the "Staff " hyper-link: What is the email address of your lab TA?

___________[See staff page for solution]____________

Part 9 Security

56. Follow the instructions in Part 9.
Then, place the screenshot of your desktop in the space below:

Here should be an image of a screenshot of the student's EWS Workstation Linux desktop. All windows should be minimized so that the desktop is showing. Verify if it is really the student's desktop by looking at the shortcut to the Home folder to see if the username listed there matches the student's netid.