function fcnpractice
delta=0.1;
x=0:0.1:100;
y=g(x,delta);
delta=0.2;
y2=g(x,delta);
plot(x,y,x,y2)
disp('press any key to continue')
pause

r=sumofcubeswhile(20);
fprintf('The sum of the first 20 cubes is %i\n',r)
disp('press any key to continue')
pause

r=sumofevencubes(20);
fprintf('The sum of the even cubes less than 21 is %i\n',r)
disp('press any key to continue')
pause

fin=inline('exp(-a*x).*sin(x)','x','a')
x=0:0.01:10;
plot(x,fin(x,0.25),x,fin(x,0.5),x,fin(x,1))
disp('press any key to continue')
pause

a=0.25;
fin=@(x, a) exp(-a*x).*sin(x)
x=0:0.01:10;
y=fin(x, a)
a=0.5;
yy=fin(x, a)
a=1;
yyy=fin(x, a)
plot(x,y,x,yy,x,yyy)
legend('a=0.25', 'a=0.5', 'a=1')
disp('press any key to continue')
pause

plot(x,ff(x,0.25),x,ff(x,0.5),x,ff(x,1))
disp('press any key to continue')
pause

i=0.001:0.0001:0.01;
y=f(i);
plot(i,y)
ii=12*fzero(@f,0.006);
fprintf('The interest rate to get $700 payment for 15 yrs is %f\n',ii)

function plotdata=g(x,delta)
plotdata=cos(x)+cos((1+delta)*x);
%
function r=sumofcubeswhile(N)
ans=0;
i=1;
while i<N+1
    ans=ans+i^3;
    i=i+1;
end
r=ans;
%
function r=sumofevencubes(N)
ans=0;
i=1;
while i<N+1
    if mod(i,2)==0
        ans=ans+i^3;
    end
    i=i+1;
end
r=ans;
%
function r=ff(x,a)
r=exp(-a*x).*sin(x);
%
function s=f(i)
p=100000;
n=360;
a=700;
s=p-a*((1+i).^n-1)./(i.*(1+i).^n);
