Tuesday, April 3, 2012

Homework # 2

2.4
 create algorithm to print
 this function based on input
Plots:


Matlab:


function ANS = P24(x,iter)

% initilizes first values
Co(1) = 1;
Err(1) =  (cos(2) - (1))/(cos(2))*1;

%loop to calculate each value based on input values
for loop = 1:iter

   t = loop  * 2 ;
   %retrieves each term for the iterations
   term = x^t/factorial(t); 
   % flips the sign
   if (mod(loop,2) == 1)
       term = -term;
   end
   %saves each value to the matrix
   Co(loop+1) = Co(loop) + term;
   Errvalue = (cos(2) - Co(loop))/(cos(2))*1;
   Err(loop+1) =  Errvalue 
end
%prints out values and graphs
Co()
Err ()
plot ((0:iter),Co,'black');
hold on;
plot ((0:iter),Err,'red');
end






2.8
algorithm to compute

F = P( 1 + i )^n
for:
P = $100,000
i = 0.06
n = 1,2,3,4,5

Matlab Code:

n = 1:5;
P = 100000;
i = 0.06;

F = P*(1 + i).^n


 

2.9
 algorithm to compute
A = P ( ( i(1 + i)^n) / ((1 + i)^n - 1)

for:
P = 55,000
i = 0.066
n = 1,2,3,4,5

Matlab Code:

n = 1:5;
P = 55000;
i = 0.066;

A = P*((i*(1+i).^n) / ((1 + i).^n - 1))




2.14
create an algorithm to compute  r , theta
based of (x,y)
and :
r = sqrt(x^2 + y^2)
theta = tan^-1 (y/x)

Matlab Code:

x = [1 1 0 -1 -1 -1 0 1 0];
y = [0 1 1 1 0 -1 -1 -1 0];

r = sqrt(x.^2 + y.^2)
theta = tan(y/x)



No comments:

Post a Comment