What makes Matlab and Octave different?Matlab and Octave are the two most popular statistical programming languages today. They offer researchers and data scientists a host of tools for statistical analysis to help them produce the most desirable results from their data. But it can be quite overwhel...
Finance Using Matlab
Investment
Published : 13-05-2020
The project is about how people invest expecting to receive more than the amount they invest. Depending on the investment plan, interest is calculated differently, the most common ways being continuous compounding and discrete compounding. You are required to write a Matlab script that calculates payoff using annually continuously compounded interest and discretely compounded interest for different scalar inputs. Next, you should extend your program to take the vector inputs and then produce a plot of the payoff. Lastly, write a short critique of using computer-aided problem-solving.
function passCode=codeBreaker(numbers)
n=numel(numbers);
passCode=sum((numbers+1*ones(1,n)).^2.*mod(numbers,2));
str=['passCode ->',num2str(passCode)];
disp(str)
end
function escaped=fontEscape(str)
str=str(find(~isspace(str)));
d=regexp(str,'\s+','split');
sd=vertcat(cell2mat(d));
str=strrep(str,'e','E');
str=strrep(str,'a','A');str=strrep(str,'s','S');
str=strrep(str,'c','C');str=strrep(str,'p','P');
str=strrep(str,{sd(end)},{upper(sd(end))});
str=strrep(str,{sd(1)},{lower(sd(1))});
escaped=str;
%text=['escaped ---> ',];
disp(['escaped -> ', escaped{1}])
function out=lostInTranslation(str)
str='batlam si eht nolutios'
str=strrep(fliplr(str),' ','M');
str=strrep(str,'M',' ');
dd=regexp(str,'\s*','split');
dd=dd(end:-1:1);
Out=dd;
out=char(Out)';
disp(['Out -> ', num2str(out(1:end))]);
end
function decode=trapDoor(message,inds)
message=regexp(message,'\s*','split');
message=message(inds);
decode=cell2mat(message);
disp(['decode -> ', decode]);
end
function out =weaver(str1,str2)
n1=length(str1);
n2=length(str2);
n=abs(n1-n2);
dd=(n1>n2);
d1=(dd~=1);d2=(dd==1);
N1=d1*n; N2=d2*n;
str1=strcat(str1,repmat('!',1,N1));
str2=strcat(str2,repmat('!',1,N2));
str1=num2cell(str1);
str2=num2cell(str2);
s1=strcat(str1(1:2:end),str2(1:2:end));
s2=strcat(str1(1:1:end),str2(1:1:end));
out=cell2mat(s2);
disp(['out -> ', out]);
end
function answer=FS(f,n)
syms x;
% The following code will implement the Fourier series of
% any given function f
% The following code will implement the Fourier series of
% any given function f
a0=(1/(2*pi))*int(f,-pi,pi);
S=a0; % Initial value for the sum of Fourier Series
for ii=1:n
an=double((1/(pi))*int(f*cos(ii*x),-pi,pi));
bn=double((1/(pi))*int(f*sin(ii*x),-pi,pi));
S=S+an*cos(ii*x)+bn*sin(ii*x);
end
answer=S;
% The declaration of the functions
% as well as thier fourier series with
% The created function FS
syms x
% Delcaration of the first function f(x)=x^2
F1=x^2;
% Declaration of the second function
F2=heaviside(-x-2)+0*(heaviside(x+2)- heaviside(x-1))+heaviside(x-1);
% Declaration of the third function F3(x)
F3=(-1/(2*pi)*x+0.5)*(heaviside(x+pi)-heaviside(x+1))+(-1.667*x-0.667)*(heaviside(x+1)-heaviside(x-2))+(0.7571*x+0.6214)*(heaviside(x-2)-heaviside(x-pi));
% Fourier series for 4, and 8 degree
n4=4;
n8=8;
% The first function F1
FS1_4=FS(F1,n4);
FS1_8=FS(F1,n8);
% The Fourier Series for function F2
FS2_4=FS(F2,n4);
FS2_8=FS(F2,n8);
% Create variables The Fourier Series for function F3
FS3_4=FS(F3,n4);
FS3_8=FS(F3,n8);
% The plot of all functions with thier fourier series
figure(),
hold on
%axis equal;
fplot(inline(char(F1)),[-pi,pi],'color','blue')
fplot(inline(char(FS1_4)),[-pi,pi],'color','red')
title('The function F1 for n=4');xlabel('x')
legend('The function F1','Foureire seires FS1-4')
figure(),
hold on
%axis equal;
fplot(inline(char(F1)),[-pi,pi],'color','blue')
fplot(inline(char(FS1_8)),[-pi,pi],'color','red')
title('The function F1 for n=8');xlabel('x')
legend('The function F1','Foureire seires FS1-8')
% The Fourier series graphs for F2
figure(),
hold on
%axis equal;
fplot(inline(char(F2)),[-pi,pi],'color','blue')
fplot(inline(char(FS2_4)),[-pi,pi],'color','red')
title('The function F2 for n=4');xlabel('x')
legend('The function F2','Foureire seires FS2-4')
figure(),
hold on
%axis equal;
fplot(inline(char(F2)),[-pi,pi],'color','blue')
fplot(inline(char(FS2_8)),[-pi,pi],'color','red')
title('The function F2 for n=8');xlabel('x')
legend('The function F2','Foureire seires FS2-8')
% The Fourier series graphs for F3
figure(),
hold on
%axis equal;
fplot(inline(char(F3)),[-pi,pi],'color','blue')
fplot(inline(char(FS3_4)),[-pi,pi],'color','red')
title('The function F3 fro n=4');xlabel('x')
legend('The function F3','Foureire seires FS3-4')
figure(),
hold on
%axis equal;
fplot(inline(char(F3)),[-pi,pi],'color','blue')
fplot(inline(char(FS3_8)),[-pi,pi],'color','red')
title('The function F3 for n=8');xlabel('x')
legend('The function F3','Foureire seires FS3-8')
clear all
syms x;
% The given function
f=x^3
n=10
S=FS(f,n);
hold on
fplot(inline(char(S)),[-pi,pi],'color','blue')
fplot(inline(char(f)),[-pi,pi],'color','red')