Vous êtes sur la page 1sur 13

Lecture HW2 Name: INSERT NAME HERE

Lecture HW2 Financial Tables


Assigned: January 26, 2011
Due: February 3, 2011----------before 11:00 a.m.

Chapra Chapter 3 3.1, 3.3, 3.3-addendum, 3.5, and 3.6

Page 1 of 13
Lecture HW2 Name: INSERT NAME HERE

Problem Statement #1: use the fprintf statement to create output table

Code for problem #1:


function coscalc(x,n)
i = 1;
tru = cos(x);
sum = 1;
fprintf('\n');
fprintf('count true value series approx error\n');
while (1)
if i>n, break, end
sum = sum + (-1)^(i)*x^(2*i) / factorial(2*i);

Page 2 of 13
Lecture HW2 Name: INSERT NAME HERE

er = ((tru - sum) / tru )* 100;


fprintf('%3d %14.10f %14.10f %12.8f\n',i,tru,sum,er);
i = i + 1;
end

Solution for problem #1:


>> coscalc(1.5,8)

count true value series approx error


1 0.0707372017 -0.1250000000 276.71041129
2 0.0707372017 0.0859375000 -21.48840776
3 0.0707372017 0.0701171875 0.87650367
4 0.0707372017 0.0707528251 -0.02208652
5 0.0707372017 0.0707369341 0.00037823
6 0.0707372017 0.0707372050 -0.00000469
7 0.0707372017 0.0707372016 0.00000004
8 0.0707372017 0.0707372017 -0.00000000
>>

Problem Statement #2: Code the formula for A into a user written function

Page 3 of 13
Lecture HW2 Name: INSERT NAME HERE

Code for problem #2:


function annualpay(P,i,n)
t = 1:n;
A = P*i*(1+i).^t./((1+i).^t-1);
y = [t;A];
fprintf('\n yr annual payment\n');
fprintf('%5d %14.2f\n',y);

Solution for problem #2:


>> annualpay(55000,0.066,5)

yr annual payment

1 58630.00

2 30251.49

3 20804.86

4 16091.17

5 13270.64

Page 4 of 13
Lecture HW2 Name: INSERT NAME HERE

Problem Statement #3:

3.3 addendum

Write code that prompts the user for


maximum interest rate minimum interest rate amount to increment the interest rate
maximum # of years minimum # of years amount to increment the years
maximum principle minimum principle amount to increment principle

Based on those inputs create a table for each of the principle amounts. The rows should have
values of payment amounts that correspond to a certain number of payoff years and the
columns should correspond to certain interest rates. Use fprintf to create the tables. See the
sample output below. Create a similar table for principle amounts of [10000:5000:30000] , for
# of years given as [3:1:7], and for the same interest rates given in the example.

Sample output for HW2 problem 3.3 addendum

principle= $200000
yrs\int 5.00% 6.00% 7.00% 8.00% 9.00% 10.00%d
5 46195 47479 48778 50091 51418 52759
10 25901 27174 28476 29806 31164 32549
15 19268 20593 21959 23366 24812 26295
20 16049 17437 18879 20370 21909 23492
25 14190 15645 17162 18736 20361 22034
30 13010 14530 16117 17765 19467 21216

principle= $300000
yrs\int 5.00% 6.00% 7.00% 8.00% 9.00% 10.00%
5 69292 71219 73167 75137 77128 79139
10 38851 40760 42713 44709 46746 48824
15 28903 30889 32938 35049 37218 39442
20 24073 26155 28318 30556 32864 35238
25 21286 23468 25743 28104 30542 33050
30 19515 21795 24176 26648 29201 31824

principle= $400000
yrs\int 5.00% 6.00% 7.00% 8.00% 9.00% 10.00%
5 92390 94959 97556 100183 102837 105519
10 51802 54347 56951 59612 62328 65098
15 38537 41185 43918 46732 49624 52590
20 32097 34874 37757 40741 43819 46984
25 28381 31291 34324 37472 40723 44067
30 26021 29060 32235 35531 38935 42432

Page 5 of 13
Lecture HW2 Name: INSERT NAME HERE

principle= $500000
yrs\int 5.00% 6.00% 7.00% 8.00% 9.00% 10.00%
5 115487 118698 121945 125228 128546 131899
10 64752 67934 71189 74515 77910 81373
15 48171 51481 54897 58415 62029 65737
20 40121 43592 47196 50926 54773 58730
25 35476 39113 42905 46839 50903 55084
30 32526 36324 40293 44414 48668 5304

Code for problem #3:


Paste code here

Solution for problem #3:


Give solution/output here

Page 6 of 13
Lecture HW2 Name: INSERT NAME HERE

Problem Statement #4:

Page 7 of 13
Lecture HW2 Name: INSERT NAME HERE

Code for problem #4:


function vol = tvol(R, d)
if d < R
vol = pi * d ^ 3 / 3;
elseif d <= 3 * R
v1 = pi * R ^ 3 / 3;
v2 = pi * R ^ 2 * (d - R);
vol = v1 + v2;
else
error('overtop')
end

Solution for problem #4:


>> tvol(1.5,1)

ans =

1.0472

>> tvol(1.5,2)

ans =

7.0686

>> tvol(1.5,4.5)

ans =

24.7400

>> tvol(1.5,4.6)
??? Error using ==> tvol at 9
overtop

Page 8 of 13
Lecture HW2 Name: INSERT NAME HERE

Problem Statement #5: The m-file must be a user written function

Page 9 of 13
Lecture HW2 Name: INSERT NAME HERE

Code for problem #5:


function [r, theta] = pcoord(x, y)
r = sqrt(x .^ 2 + y .^ 2);
if x < 0
if y > 0
theta = atan(y / x) + pi;
elseif y < 0
theta = atan(y / x) - pi;

Page 10 of 13
Lecture HW2 Name: INSERT NAME HERE

else th = pi;
end
else
if y > 0
theta = pi / 2;
elseif y < 0
theta = -pi / 2;
else
theta = 0;
end
end
theta = theta * 180 / pi;

Solution for problem #5:


>> [r,theta]=pcoord(1,0)

r=

theta =

>> [r,theta]=pcoord(1,1)

r=

1.4142

theta =

90

>> [r,theta]=pcoord(0,1)

r=

theta =

Page 11 of 13
Lecture HW2 Name: INSERT NAME HERE

90

>> [r,theta]=pcoord(-1,1)

r=

1.4142

theta =

135

>> [r,theta]=pcoord(-1,0)

r=

theta =

180

>> [r,theta]=pcoord(-1,-1)

r=

1.4142

theta =

-135

>> [r,theta]=pcoord(0,0)

r=

theta =

Page 12 of 13
Lecture HW2 Name: INSERT NAME HERE

>> [r,theta]=pcoord(0,-1)

r=

theta =

-90

>> [r,theta]=pcoord(1,-1)

r=

1.4142

theta =

-90

Page 13 of 13

Vous aimerez peut-être aussi