Find maximum of a function

Hi,
I am new to Matlab. I was using Mathematica before. I am writing a code for a research paper (in economics. I attach it below. It probably is not written in the best possible way, but it works until the last line.
I would like to evaluate totaltax(t1,t2) for each (t1,t2) with t1 in 0:step:1 and t2 in 0:step:1. My objective is then to find the (t1,t2) combination which maximizes totaltax.
I tried to use meshgrid, but did not manage to get what I wanted. So I am presently stuck. Your help would be much appreciated! Best,
Laurent
kmax = 5; % I will increase it later
mu1 = 10.19357; % mean of log wages omega
sigma1 =0.3022616; % standard deviation of log wages
mu2 = 11.795; % mean of shifting cost gamma
sigma2 = 0.1*11.795; % 10% of the mean cost
rho=-0.2;
elastmean=0.2;
elastsd=1/2*elastmean;
step=0.1;
%%%%%%%%%%%%%%%%%%%%%%%%
mu=[mu1 mu2];
sigma=[sigma1 sigma2];
corr=[1 rho*sigma1*sigma2; rho*sigma1*sigma2 1];
data=MvLogNRand(mu,sigma,kmax,corr);
omega=data(:,1); %column vector with skills
gamma=data(:,2); %column vector with shifting costs
plot(omega,gamma,'+');
ppd=makedist('Normal','mu',elastmean,'sigma',elastsd);
tt=truncate(ppd,0,1);
elasticity=random(tt,kmax,1); % elasticities defined from normal draw
threshold=@(t1,t2,elast,g) (((1.+elast).*g)./((1-t2).^(1.+elast)-(1-t1).^(1.+elast))).^(1./(1.+elast));
omegatilde=@(t1,t2) threshold(t1,t2,elasticity,gamma); % shifting if omega > omegatilde
shift=@(t1,t2) omega>omegatilde(t1,t2); % vector with 1 for shifters and 0 for non-shiftersshift(1,0)
noshift=@(t1,t2) omega<=omegatilde(t1,t2); % vector with 0 for shifters and 1 for non-shiftersshift(1,0)
tax1=@(t1,t2) t1.*(1.-t1).^elasticity.*omega.^(1.+elasticity);
tax2=@(t1,t2) t2.*(1.-t2).^elasticity.*omega.^(1.+elasticity);
indtax=@(t1,t2) tax1(t1,t2).*noshift(t1,t2)+tax2(t1,t2).*shift(t1,t2);
totaltax=@(t1,t2) sum(indtax(t1,t2));

2 commentaires

Stephen23
Stephen23 le 26 Jan 2019
If the functions are fully vectorized then ndgrid or meshgrid to get the values, call the function with those values, and then find the minimum. Otherwise you will have to use a loop or arrayfun.
Laurent Simula
Laurent Simula le 27 Jan 2019
Thanks a lot! I managed to get what I wanted with a loop.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Modify Image Colors dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by