The Use of Heaviside function in integration
7 views (last 30 days)
Show older comments
This code is working fine without the use of heaviside fuction. But I need to control the graph movement with the heaviside fuction.
Please help me out.
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);
n2(i)= integral(fun2*heaviside(I2)-(0.05*L),t05,tau); %please help
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)
3 Comments
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
n2(i)= integral(fun2*heaviside(I2)-(0.05*L),t05,tau); %please help
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.
n2(i)= integral(fun2*heaviside(I2)-(0.05*L),t05,tau); %please help
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:
n2(i)= integral( @(t)fun2(t)*heaviside(I2(t))-(0.05*L),t05,tau); %please help
Answers (0)
See Also
Categories
Find more on Assumptions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!