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

Computational Methods for

a
vi
Engineering

ed
ar
sh
as
w
m e
co rc
o. ou
Instructor: Dr. Nguyen Quang Hung
er res

Week 5:
se dy
ur tu

Programming with MATLAB


s
H
is

(continue)
Th

https://www.coursehero.com/file/9247447/Week5-Programming-with-MATLAB-II/
Problem 3.2

a
vi
An amount of money P is invested in an account where
interest is compounded at the end of the period. The future

ed
worth F yielded at an interest rate i after n periods may be

ar
determined from the following formula:

sh
F = P(1 + i )n

as
Write an M-file that will calculate the future worth of an

w
investment for each year from 1 through n. The input to the

m e
function should include the initial investment P, the interest

co rc
o. ou
rate i (as a decimal), and the number of years n for which the
future worth is to be calculated. The output should consist of
er res
a table with headings and columns for n and F. Run the
se dy

program for P = $100,000, i = 0.05, and n = 10 years.


ur tus
H
is
Th

https://www.coursehero.com/file/9247447/Week5-Programming-with-MATLAB-II/
Solution to #3.2

a
vi
clc; clear all;

ed
P=100000;

ar
i=0.05;

sh
n=10;

as
fprintf(' n F \n');

w
m e
for j=1:n

co rc
F(j)=P*(1+j).^n; o. ou
fprintf('%2d %13.5e \n',[j,F(j)]);
er res
end
se dy
ur tus
H
is
Th

https://www.coursehero.com/file/9247447/Week5-Programming-with-MATLAB-II/
Problem 3.3

a
vi
Economic formulas are available to compute annual
payments for loans. Suppose that you borrow an amount of

ed
money P and agree to repay it in n annual payments at an

ar
interest rate of i. The formula to compute the annual payment

sh
A is

as
n
i(1+ i)

w
A=P n

m e
(1+ i) !1
co rc
o. ou
Write an M-file to compute A. Test it with P = $100,000 and
er res
an interest rate of 3.3% (i = 0.033). Compute results for n =
se dy

1, 2, 3, 4, and 5 and display the results as a table with


headings and columns for n and A.
ur tus
H
is
Th

https://www.coursehero.com/file/9247447/Week5-Programming-with-MATLAB-II/
Solution to #3.3

a
vi
clc; clear all;

ed
P=100000;

ar
i=0.033;

sh
n=5;

as
fprintf(' n A \n');

w
for j=1:n

m e
co rc
A(j)=P*(j*(1+j).^n/((1+j).^n-1)); o. ou
fprintf('%2d %13.5e \n',[j,A(j)]);
er res
end
se dy
ur tus
H
is
Th

https://www.coursehero.com/file/9247447/Week5-Programming-with-MATLAB-II/
Problem 3.6

a
vi
2 2 " y%
!1
r = x + y ; ! = tan $ '

ed
#x&

ar
sh
Write a well-structured
M-file using if...elseif

as
structures to calculate r

w
and θ as a function of x

m e
co rc
and y. Express the
o. ou final results for θ in
er res
degrees. Test your
program by evaluating
se dy

the following cases:


ur tus
H
is
Th

https://www.coursehero.com/file/9247447/Week5-Programming-with-MATLAB-II/
Solution to #3.6

a
vi
clc;clear all; elseif x(i)==0
x=[2,2,0,-3,-2,-1,0,0,2]; if y>0

ed
y=[0,1,3,1,0,-2,0,-2,2]; theta(i)=pi/2;

ar
r=sqrt(x.^2+y.^2); elseif y>0

sh
disp('--------------------------'); theta(i)=-pi/2;
disp('x y r theta '); else

as
disp('--------------------------'); theta(i)=0;

w
for i=1:length(x) end

m e
if x(i)<0 else

co rc
if y(i)>0 theta(i)=1/tan(y(i)/x(i));
theta(i)=1/tan(y(i)/x(i))+pi; o. ou end
er res
elseif y(i)<0 fprintf('%2d %2d %6.2f %6.2f \n',x(i),y
theta(i)=1/tan(y(i)/x(i))-pi; (i),r(i),theta(i));
se dy

else end
theta(i)=pi; disp('--------------------------');
ur tu

end
s
H
is
Th

https://www.coursehero.com/file/9247447/Week5-Programming-with-MATLAB-II/
Homework Assignment

a
vi
ed
ar
sh
as
w
Problems: 3.9, 3.10, 3.13, 3.14, 3.23

m e
co rc
o. ou
er res
se dy
ur tus
H
is
Th

https://www.coursehero.com/file/9247447/Week5-Programming-with-MATLAB-II/
Powered by TCPDF (www.tcpdf.org)

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