# The Use of Heaviside function in integration

6 views (last 30 days)
JACINTA ONWUKA on 17 Oct 2019
Commented: Walter Roberson on 17 Oct 2019
This code is working fine without the use of heaviside fuction. But I need to control the graph movement with the heaviside fuction.
L=1;
T=100;
r=0.03;
I1=0.25;
p=0.0005;
epsilon=1;
Myrho=0:60:6000;
MycpBest=zeros(numel(Myrho),1);
JCpBest=zeros(numel(Myrho),1);
Mybeta =0.0001:0.002999:0.3;
for ii = 1:numel(Mybeta)
beta=Mybeta(ii);
for j = 1:numel(Myrho)
rho=Myrho(j);
Mycp = 0:10:100; %area cost of PM without RM
n = zeros(numel(Mycp),1 );
n2 = zeros(numel(Mycp),1 );
n3 = zeros(numel(Mycp),1 );
Jcp = zeros(numel(Mycp),1 );
for i = 1:numel(Mycp )
MycpCurrent=Mycp(i)-0.1;
delta = 1-MycpCurrent/100;
tau = (1/(beta*(L+delta*p)))*log((L*(I1+delta*p))/(delta*p*(L-I1 )));
t05 =(1/(beta*(L+delta*p)))*log((L*(0.05*L+delta*p))/(delta*p*(L-0.05*L )));
I2= @(t)(L*delta*p*(exp (beta*(L+delta*p)*t)-1)) ./ (L + delta*p* exp(beta*(L+delta*p)*t ));
I3= @(t)(L*(I1+delta*p)*exp((epsilon*beta)*(L+delta*p)*(t-tau))-...
delta*p*(L -I1))./(L-I1+(I1+delta*p)*exp(epsilon*beta*(L+delta*p)*(t-tau)));
%function of integration
fun = @(t,MycpCurrent) MycpCurrent*L*exp(-r*t);
fun2=@(t)rho*I2(t).*exp(-r*t);
fun3=@(t)rho*I3(t).*exp(-r*t);
% integration
n(i) = integral(@(t)fun(t,MycpCurrent),0,100, 'ArrayValued',1);
n3(i)= integral(fun3*heaviside(I3)-(0.05*L),tau,100);
% Jp(cp)
JCp(i)= n(i)+n2(i)+n3(i);
end
MycpBest(j,ii)=Mycp(JCp==min(JCp)); %minimum of jp(cp)
JCpBest(j,ii)=min(JCp); %Cp star
end
end
%imagesc(Mybeta,Myrho,JCpBest)
imagesc(Mybeta,Myrho,MycpBest)
Walter Roberson on 17 Oct 2019
I2= @(t)(L*delta*p*(exp (beta*(L+delta*p)*t)-1)) ./ (L + delta*p* exp(beta*(L+delta*p)*t ));
I2 is a function handle
heaviside is a function from the symbolic toolbox. It requires that the input be single, double, or symbolic expression or symbolic function. Function handle is not one of the possibilities.
fun2=@(t)rho*I2(t).*exp(-r*t);
fun2 is a function handle.
You are trying to multiply a function handle by a value. If I2 were a symbolic function instead of a function handle, then because heaviside happens to be from the symbolic toolbox, it turns out that multiplying a function handle by a symbolic expression is defined, and is equivalent to invoking the function handle on a symbolic variable with the same name as the dummy parameter for the function handle... which is not necessarily going to be the right variable name for the purpose of integration.
If you managed to get past that stage, then the result of the multiplication would be symbolic, and you would be trying to apply integral() to a symbolic expression, which would fail.
You need to invoke your functions: