The idea is to produce 2D image but is not working. I want each square to correspond to different values of rho(1×101) and beta(1×101) for JCpBest(101×101). please help me
close allclear all % general parameters; will be fixed for all runs
L=1;T=100;r=0.03;I1=0.5; % we will be changing P and epsilon to generate grous of graphs
p=0.0005;epsilon=0.3; % individual policy plots will be generated by a double loop
% over beta and rho
beta=0.1;rho=6000; Mybeta=0:0.003:0.3;Myrho=0:60:6000;MycpBest=zeros(numel(Myrho),1);JCpBest=zeros(numel(Myrho),1); for j = 1:numel(Myrho) rho=Myrho(j); for ii = 1:numel(Mybeta) beta=Mybeta(ii); % the inner loop will be over Mycp, to find its 'best' value which
% minimmises the loss; here this value is fixed to see what happens
% create an index vector
Mycp = 0:10:100; 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);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))); fun = @(t,MycpCurrent) MycpCurrent*L*exp(-r*t);fun2=@(t)rho*I2(t).*exp(-r*t);fun3=@(t)rho*I3(t).*exp(-r*t); n(i) = integral(@(t)fun(t,MycpCurrent),0,100, 'ArrayValued',1);n2(i)= integral(fun2,t05,tau);n3(i)= integral(fun3,tau,100);JCp(i)= n(i)+n2(i)+n3(i); end MycpBest(j)=Mycp(JCp==min(JCp));JCpBest(j)=min(JCp);endend imagesc(Mybeta,Myrho,JCpBest)colormap jetylim([0 6000]);xlim([0 0.3]);ylabel('Loss,\rho_1');xlabel('Secondary disease transmission rate \beta ');title('P=0.0005')
Best Answer