You are on page 1of 3

ANSWERS to WEEK 4

PRACTICAL

1.
>>x=A\b
x=[4;-1]
2. A=[2 3 1 4;4 3 2 1;1 2 3 4]
rref(A)
ans =
1.0000
0
0 -1.6667
0 1.0000
0 2.3333
0
0 1.0000 0.3333
3.
function y = staircase(x)
if x<=1
y=0;
elseif x<=2
y=1;
else
y=2;
end
4.
>> x.*y
ans =

>> x*y'
ans =
10

5.
T=randn(1,121)*2+70;
t=0:120;
plot(t,T)
[maximum, element]=max(T)
max_Temp_time=t(element)
[minimum, element]=min(T)
min_Temp_time=t(element)

6.
G = [68, 83, 61, 70, 75, 82, 57, 5, 76, 85, 62, 71, 96, 78, 76, 68, 72, 75,
83, 93];
sorted_grades = sort(G)
figure(2)
subplot(1,2,1)
bar(sorted_grades)
title('Test Results')
xlabel('Student Number')
ylabel('Score')
subplot(1,2,2)
hist(G)
title('Test Results')
xlabel('Score')
ylabel('# Students')

HOMEWORK
1.
times=0:2:24;
load thermocouple.dat
table = [times',thermocouple]
[maximum,element]=max(thermocouple)
maxtime=times(element)

2.
balance(1)=1000;
years=18;
monthly_savings =100;
months = 18*12;
for k=2:months
balance(k)=balance(k-1) + balance(k-1)*.005 +
monthly_savings;
end
time=1:months;
time=time/12;
plot(time,balance)
title('College Savings')
xlabel('years')
ylabel('Balance')
fprintf('At the end of 18 years you''ll have %10.0f dollars
\n',balance(months))

You might also like