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

Stephen23
Stephen23 2019년 1월 26일
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 2019년 1월 27일
Thanks a lot! I managed to get what I wanted with a loop.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Modify Image Colors에 대해 자세히 알아보기

제품

질문:

2019년 1월 26일

댓글:

2019년 1월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by