Briana Smith
PHYS108 Exam 01
QUESTION 2. Write a short function to determine the second largest
element for an input vector, x.
function sec_largest(x)
sorted_vec = sort(x);
sec = sorted_vec(length(sorted_vec) - 1);
fprintf('%1.0d\n', sec);
end
EDU> sec_l
PHYS108 HW_04 String Manipulation
1) Create a function, termed random_lower_letter, which returns a random lower letter of
alphabet.
function letIn = random_lower_letter
letIn = char(randi([97 122], 1,1);
end
EDU> random_lower_letter
ans =
m
EDU> random_l
PHYS_108 Exam 2
QUESTION 1
function month(length, start)
day = 1;
count = start;
weeks = cell(5,7);
%populate the first week at the appropriate start day
for a = 1:7-start+1
weeks(1, count:end) = cfw_day;
count = count+1;
day = day+1;
end
%if the month st
PHYS108 HW_06
1) Read a text file, random_integers.txt, that contains a list of ten integers of arbitrary
size, stored
one integer per line. Write a function to read this list and write it to a second file with
the order of the
numbers reversed.
function
PHYS108_HW05
1) Create a function that will generate two random integers in the range 10 to 99. It will return a string
consisting of the two integers joined together. (e.g., if the random integers are 11 and 29, the string
returned will be 1129).
functio
PHYS108 hw_02 MATLAB Expressions and Matrix Manipulation
1) Work out the results of the following expressions:
a = [-1 0 3]; b = [0 3 1];
a. ~a
b. a & b
c. a | b
d. a > 0 & b > 0
e. a > 0 | b > 0
f. ~ a > 0
g. ~ a > b
h. ~ ( a > b)
a. the not function is
PHYS108 Home Work 1
DUE: Monday 09/23/2013 at 5 PM.
You may want to use the d iary command to create the homework. If you do so, you must edit your diary
output to remove any errors!
1.
2.
Evaluate these
your answers!
a)
b)
c)
d)
e)
MATLAB expressions be
9/23/13
phys108_hw01
%
cfw_
BIN SIH
RAA MT
PY18H 0
HS0 W 1
%
%USIN1
QETO
1+2*3
%utocr frt
ml cus is
as=
n
7
(./.)2 %iiinwti teprnhssfrtte epnn
2030^
dvso ihn h aetee is hn xoet
as=
n
044
.44
%
cfw_
mlilcto addvso hv eulpirt s Mta
utpiain n iiin ae qa roi
Vectors and Number Manipulation
PHYS108 HW_03
1) Create the following variable:
x = 12.34;
y = 4.56;
Then ll in the fprintf using these variables to accomplish the following:
> fprintf(
x is 12.340
> fprintf(
x is 12
> fprintf(
y is 4.6
> fprintf(
Y is 4