Solve和NSolve适用于大型模型

时间:2014-07-24 21:39:55

标签: algorithm wolfram-mathematica

我是2010年MacBook Pro上运行第7版的Mathematica新手。

我试图解决与大量公司的经济问题,每个公司都有最大的生产配额(即生产权)。这些公司的规模不同,较大的公司比小公司更有效率。有一个配额市场,因此小型低效率的公司可以关闭并将配额权出售给较大的配额;配额价格k必须是内生计算的。

问题如下:少数公司n(从2到3),只有Solve工作,而NSolve给我{},即没有解决方案。 只有中等数量的公司(从4到7),只有NSolve有效。 有8家和9家公司,NSolve生产{}。 有10到16家公司,NSolves运作良好。 有更多的公司(17岁及以上),评估一直没有结束,我最终中止(我等了15分钟)。

我的希望是与数千家公司合作运行该模型。我的问题是(1)我如何系统地让Mathematica收敛到任意大型系统的解决方案;(2)为什么NSolve不适用于小型系统。

两个评论:

(1)你会注意到我设置模型的方式有些笨拙,从k的猜测k0开始,它决定哪些公司在运营,哪些公司正在关闭。然后,对于运营公司列表,我计算利润最大化的劳动量,总产出和均衡k。如果k与k0不同,我用k0 = k重新开始计算。然而,如何创建更优雅的一步式程序的问题是一个单独的问题,我并不认为它与模型大小限制有关。

(2)如果我为11家公司解决模型,然后试图解决13家公司的问题,那么Mathematica最终会无休止地运行"。但如果我首先解决12家公司,那么解决13家公司只需几秒钟。所以看起来尽管笔记本开头的ClearAll [" Global` *"]语句,似乎Mathematica似乎从一个更好的起点开始。

我准备好谦卑:)

以下是代码:

ClearAll["Global`*"]
(* Aggregate Quota Allocation *)
alloc=1000000;
(* Number of firms; *)
nv=4;
(* Equal quota allocation to each firm; *)
qbar = alloc/nv;
(* Firm sizes vary in amount of capital from smallest to largest;*)
vsmin=0 ;
vsmax=900000 ;
(* Assume discrete uniform distribution of firm sizes;*)
dvs=(vsmax-vsmin)/(nv-1) ;
(* List all firms by size; *)
listvs=Table[vs,{vs,vsmin,vsmax,dvs}]  ;
(* A firm's capital cost per annum is 10 percent of capital size;*)
g=0.1 ;
(* Avoidable fixed cost of operation;*)
f=5000 ;
(* Parameters of production function (same for all firms);*)
a=0.01 ;
alpha=0.7 ;
(* Price of output; *)
p=5;
(* Price of labor (daily wage);*)
wa=100 ;
(* Firm vs is a profit maximizer setting optimal number of days of operation tl[vs] ;
Firms that are too small are better off leasing their quota allocation to larger ones; 
The quota leasing price k is computed endogenously;
Firms will exit if "netprofitstay" is less than 0;
We are looking for threshold firm, whose size nvs1 is just above threshold size vs0;
All firms who size is nvs1 or larger are operating, the others are shutting down;
For now, we are setting the problem up as a manual loop, setting k0 = "k opt" 
from previous computation ; *)

k0=4.891714989052472` ;

profitstay0[tl0_,vs0_]:= (p-k0)(a vs0 tl0^alpha) - wa tl0 + k0 qbar - g vs0 - f  ;
netprofitstay0[tl0_,vs0_]:=(p-k0)(a vs0 tl0^alpha) - wa tl0 - f  ;
sol0:=NSolve[{D[profitstay0[tl0,vs0],tl0]==0 ,netprofitstay0[tl0,vs0]==0} ,{tl0,vs0}]  ;
vs1:=vs0/.Last[sol0] 
nvs0:=Part[Nearest[listvs,vs1],1] ;
nvs1:=If[nvs0<vs1,nvs0+dvs,nvs0] ;
(* List of firms who operate when k=k0; *)
listvsop:=Table[vs,{vs,nvs1,vsmax,dvs}]  ;

(* Production function;*)
eq[tl[vs_],vs_]:=a vs tl[vs]^alpha ;
(* Profit; *)
profitstay[k_,tl[vs_],vs_]:=(p-k) eq[tl[vs],vs] - wa tl[vs] + k qbar - g vs - f  ;
(* List of first-order conditions for a maximum; *)
foc:=Table[D[profitstay[k,tl[vs],vs],tl[vs]]==0,{vs,listvsop}]  ;
(* List of all endogenous variables; *)
variables:=Flatten[{k,Table[tl[vs],{vs,listvsop}]},1] ;
Print[variables] ;
(* List of all equations, including the one specifying that aggregate quota demand = aggregate
quota supply; *)
equations:=Flatten[{foc,Sum[eq[tl[vs],vs],{vs,listvsop}]==alloc }] ;
Print[equations] ;

(* Find solution;*)
NSolve[equations,variables]

0 个答案:

没有答案
相关问题