全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 MATLAB等数学软件专版
1705 0
2009-06-21
哪位达人比较熟悉gams,现在有以下问题需要帮忙:
Rt = ∑ωirit   
这里i 为作物生长阶段个数, Rt为第t年的降雨指数,ωi是第i个阶段的降水权重值,rit是第t年第i个阶段的降水量
优化目标:使得产量Yt(t年的产量)与的Rt相关系数最大。
   
代码如下,在方程部分出错,信息如下:
**** Exec Warning 40 at line 69 ..
     Derivative for sqrt(0) is undefined - set to 1e10

**** Exec Error 0 at line 69 .. Division by zero

请高手帮忙看看,多谢~~

————————————————————————
sets i days in growth period /1*5/
     t simulation period /2000*2004/
parameter r(i,t) rainfall in n days  /1 .2000        213.4
                                    2 .2000        255.7
                                    3 .2000        173.5
                                    4 .2000        35.4
                                    5 .2000        185.6
                                    1 .2001        212.4
                                    2 .2001        156.6
                                    3 .2001        140.4
                                    4 .2001        102.3
                                    5 .2001        208.3
                                    1 .2002        181.6
                                    2 .2002        273.4
                                    3 .2002        173.1
                                    4 .2002        253.3
                                    5 .2002        150.6
                                    1 .2003        113.8
                                    2 .2003        258.2
                                    3 .2003        208.8
                                    4 .2003        11.3
                                    5 .2003        60.9
                                    1 .2004        237.9
                                    2 .2004        258.7
                                    3 .2004        148.0
                                    4 .2004        109.8
                                    5 .2004        150.4 /;


parameter y(t) annual yield /2000        1489.1
                           2001        1236.5
                           2002        1623.3
                           2003        1048.1
                           2004        1361.7
                            /;
alias(t,t1,t2,t3);
alias(i,i1,i2,i3);
scalar yav average annual yield;
yav = sum(t,y(t))/card(t);
Variable w(i) weight of daily rainfall;

         w.lo(i) = 0;

Variable cc correlation coefficient between rainfall index and yeild;

Equations
         corr define objective function
         wsum satisfy condition;
         wsum .. sum(i,w(i)) =e= 1;
         corr .. cc =e= sum(t,(sum(i, w(i)*r(i,t))-
                        sum(t1,sum(i,w(i)*r(i,t1)))/card(t1))*
                         (y(t)-yav))
                         /
                         (sqrt(sum(t2,sqr(sum(i, w(i)*r(i,t2))-
                         sum(t3,sum(i,w(i)*r(i,t3)))/card(t3))))*
                         sqrt(sum(t,sqr(y(t)-yav))));

model derive_weight /all/;
solve derive_weight using nlp maximizing cc;

file wout this defines outfile of the weight  /w-out.txt/
put wout;
loop(i, put w(i))
putclose wout;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群