Вы находитесь на странице: 1из 3

HW 1 (10 pts)

Introduction to M ATLAB

CENG 15
Fall 2016: Dr. Drews

Create a single M ATLAB script and save it as xyz123_hw1.m where xyz123 is your UC San Diego e-mail address
without the @ucsd.edu part (e.g., adrews_hw1.m, not adrews@ucsd.edu_hw1.m). The first three variables you
define should be myName as a string, myPID as a number, and myEmail as a string (use your UCSD e-mail), like
so:
1
2
3
4
5
6

% User information:
myName = 'Aaron Drews';
myPID = 12345678;
myEmail = 'adrews@ucsd.edu'; % always include the '@ucsd.edu' part!
% The rest of your HW assignment answers start here.

Complete each exercise within this single script. Use a semicolon ( ; ) at the end of all statements to suppress outputs. If your script throws an error when executed then you will receive a score of zero for this HW.
Remember to follow the directions closely, using variables names exactly as noted if youre asked to assign a
particular result to a variable. Keep in mind that variables are case sensitive (myname is not the same as myName).
If you make any intermediate variables be sure not to overwrite old variables (i.e., always use unique variable
names).
(P1.1) Create the variable m_earth_kg and assign to it the mass of Earth, 5.972 1024 kg. Convert this unit to
pounds and assign the result to the variable m_earth_lb. The conversion factor is 1 kg = 2.2 lb.
(P1.2) Create the variable bp_water_degC and assign to it the boiling point of water, 100 C. Convert this
unit to degrees Rankine and assign the result to the variable bp_water_degR. The conversion factor is
R = (C + 273.15) 9/5.
(P1.3) The combined resistance RT of three resistors R1 , R2 , and R3 in parallel is given by
1
1
1
1
=
+
+ .
RT
R1 R2 R3
Create variables R1, R2, and R3 and assign resistances of 10 , 50 , and 35 to each variable respectively,
and then calculate the combined resistance RT and assign the result to the variable RT.
(P1.4) Create variables a1, a2, and a3 and assign to each the following numerical values:

a1 = 19
a2 = 312
a3 = tan
(P1.5) A vector can be represented by its rectangular coordinates x and y or by its polar coordinates r and . The
relationship between them is given by the equations
x = r cos
y = r sin
Determine r and for the coordinates x = 3 and y = 4 and assign the results to variables r and theta.

Pg. 1 of 3

HW 1 (10 pts)
Introduction to M ATLAB

CENG 15
Fall 2016: Dr. Drews

(P1.6) In special relativity the Lorentz factor is a number that describes the effect of the speed on various
physical properties when the speed is significant to the speed of light. Mathematically, the Lorentz factor
is
1
,
=q
u2
1 c2
where u is the speed of interest and c = 3 108 m s1 is the speed of light. Create the variable gamma and
assign to it the Lorentz factor for a human walking speed of 1 m s1 .
(P1.7) The geometric mean g of n numbers is defined as the nth root of the product of all the numbers,
g = (x1 x2 x3 xn )1/n .
This is a useful formula if, for example, youd like to determine the average rate of return for an investment,
in which case each xi term represents the rate of return for an individual year and n is the number of years
during which the investment is held. Determine the average rate of return for an investment that returns
15% the first year, 50% the second year, and 25% the third year and assign the result to the variable g.
Report your answer as a percentage, not a decimal (i.e., for 6% report 6, not 0.06).
(P1.8) Use the Command Window to evaluate each of the commands below and determine the class of each
answer (e.g., double, logical, char, etc.) by looking at the result in the Workspace. Store the class
of each answer as a string in your script as variables c1, c2, c3 etc., where c1 is the class of the first
commands result, c2 is the class of second commands result, and so forth. If the command results in an
error, assign to that command the string 'error'. For example, for the commands
c1: >> 10
c2: >> 'ten'
c3: >> ten
you would create variables c1 = 'double', c2 = 'char', and c3 = 'error' in your script because
entering 10 in the Command Window results in an answer of class double, 'ten' results in an answer of
class char, and ten results in an error.
c1:
c2:
c3:
c4:
c5:
c6:

>>
>>
>>
>>
>>
>>

6 + 6
tan(6 + 6)
tan(six + six)
tan('six'+ 'six')
tan(pi + pi)
tan('pi')

c7: >> 'b' >= 'c'


c8: >> 'b' == 'b'
c9: >> {'six'}
c10: >> [1 2 3 4]
c11: >> uint32(15 * rand(1, 1))
c12: >> h = surf(membrane)

(P1.9) For each question below, let x = 3 and y = 4, and then use logical operators to decide if each statement is
true or false. Create variables q1, q2, etc. to hold the result as a logical (true or false). For example,
for the question
q1: Is x greater than y?
you would create the variable q1 = false in your script because x > y evaluates to a 0 logical.
q1: Is x less than y, and is xy equal to 10?
q2: Is y less than x, or is xy equal to 10?
Pg. 2 of 3

HW 1 (10 pts)
Introduction to M ATLAB
q3: Is 'a' + 26 the same as 'A'?
q4: Is (x2 + y2 )1/3 less than six, and is the absolute value of ei + 1 less than 1014 ?
q5: Is sin2 x + cos2 x = 1, and is 2 cos2 x = 1 + sin 2x?

Pg. 3 of 3

CENG 15
Fall 2016: Dr. Drews

Вам также может понравиться