24小时热门版块排行榜    

CyRhmU.jpeg
查看: 4036  |  回复: 16

sunjiahuan

铜虫 (小有名气)

[求助] matlab求解非线性方程组已有1人参与

I1=(1.3403/0.323)*(354.3091/443.6719-lambertw((1.0885e-004/443.6719)*exp((330.7*x1+354.3091)/443.6719)))-x1/(0.323+330.7)+1.019*10^(-6)*(exp(x1/1.3403)-1);
I2=(1.3403/0.323)*(349.7334/437.9477-lambertw((1.0744e-004/437.9477)*exp((326.4292*x2+349.7334)/437.9477)))-x2/(0.323+326.4292)+1.019*10^(-6)*(exp(x2/1.3403)-1);
I3=(1.3403/0.323)*(337.973/423.2354-lambertw((1.0383e-004/423.2354)*exp((315.4524*x3+337.973)/423.2354)))-x3/(0.323+315.4524)+1.019*10^(-6)*(exp(x3/1.3403)-1);
I4=(1.3403/0.323)*(324.4644/406.3363-lambertw((9.9677e-005/406.3363)*exp((302.844*x4+324.4644)/406.3363)))-x4/(0.323+302.844)+1.019*10^(-6)*(exp(x4/1.3403)-1);
I5=1.019*10^(-6)*(exp(x5/1.3403)-1);
上面是5个方程,I1=f(x1),I2=f(x2),I3=f(x3),I4=f(x4),I5=f(x5); 关于方程里的lambertw函数,可以在附件(太阳电池I-V方程显示求解原理研究及应用中的第二章中找到)。

而要求解的方程组是由它们5个组成的,如下:
x1+x2+x3+x4+x5-30=0
I1-I2=0;
I1-I3=0;
I1-I4=0;
I1-I5=0;
上面的方程组已经写好,在fun.m里。

而在dfun.m 中是方程组里的每一个方程分别对x1,x2 x3 x4 x5 求一阶导数。其实就是求方程组的雅克比矩阵;

在newton.m里是求解的编程,是我在这个网上(http://hi.baidu.com/aillieo/blog ... c9a59647106493.html)找到的,只是把里面的方程及相关部分改了一下。

我在matlab里输入newton([0.01 0.01 0.01 0.01 0.01],0.00001,200)
最后得到的结果是
In newton at 6
Warning: Matrix is singular, close to singular or badly scaled.
         Results may be inaccurate. RCOND = NaN.
> In newton at 6

ans =

   NaN   NaN   NaN   NaN   NaN。
这种方法是好多学者用过的,得到的结果都挺好。所以方法应该没问题。因为我的matlab只学了个皮毛,不知道这里面哪出错了,还请各位高手给指点一下。
回复此楼

» 本帖附件资源列表

  • 欢迎监督和反馈:小木虫仅提供交流平台,不对该内容负责。
    本内容由用户自主发布,如果其内容涉及到知识产权问题,其责任在于用户本人,如对版权有异议,请联系邮箱:xiaomuchong@tal.com
  • 附件 1 : newton.m
  • 2012-02-22 16:56:51, 775 bytes
  • 附件 2 : dfun.m
  • 2012-02-22 16:56:51, 120 bytes
  • 附件 3 : fun.m
  • 2012-02-22 16:56:52, 969 bytes
  • 附件 4 : 太阳电池I_V方程显式求解原理研究及应用.nh
  • 2012-02-22 16:57:53, 4.29 M

» 收录本帖的淘帖专辑推荐

材料+新能源+催化+外语

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
回帖支持 ( 显示支持度最高的前 50 名 )

dbb627

荣誉版主 (著名写手)

【答案】应助回帖

感谢参与,应助指数 +1
ben_ladeng(金币+2): 谢谢应助 2012-02-22 21:59:15
ben_ladeng(专家考核): 2012-02-22 21:59:24
caemechanics(金币+5): 感谢应助 2012-02-23 16:18:30
错误提示信息是矩阵奇异,
可能初值不太合适
我用自带fsolve解了下
结果不是很好
[/code]
function aa
[X,FVAL,EXITFLAG,OUTPUT] =fsolve(@fun,[18.7783   0.01   18.1315   18.0062  -2],optimset('MaxFunEvals',1000))
function f=fun(x)
x1=x(1);
x2=x(2);
x3=x(3);
x4=x(4);
x5=x(5);
f1=x1+x2+x3+x4+x5-30;
f2=4.1495*(0.7986-lambertw(2.4534e-007*exp((330.7*x1+354.3091)/443.6719)))-x1/331.0230+1.019e-6*(exp(x1/1.3403)-1)-4.1495*(0.7986-lambertw(2.4533e-007*exp((326.4292*x2+349.7334)/437.9477)))+x2/(0.323+326.4292)-1.019*10^(-6)*(exp(x2/1.3403)-1);
f3=4.1495*(0.7986-lambertw(2.4534e-007*exp((330.7*x1+354.3091)/443.6719)))-x1/331.0230+1.019e-6*(exp(x1/1.3403)-1)-4.1495*(0.7985-lambertw(2.4532e-007*exp((315.4524*x3+337.973)/423.2354)))+x3/(0.323+315.4524)-1.019*10^(-6)*(exp(x3/1.3403)-1);
f4=4.1495*(0.7986-lambertw(2.4534e-007*exp((330.7*x1+354.3091)/443.6719)))-x1/331.0230+1.019e-6*(exp(x1/1.3403)-1)-4.1495*(0.7985-lambertw( 2.4531e-007*exp((302.844*x4+324.4644)/406.3363)))+x4/(0.323+302.844)-1.019*10^(-6)*(exp(x4/1.3403)-1);
f5=4.1495*(0.7986-lambertw(2.4534e-007*exp((330.7*x1+354.3091)/443.6719)))-x1/331.0230+1.019e-6*(exp(x1/1.3403)-1)-1.019*10^(-6)*(exp(x5/1.3403)-1);
f=[f1 f2 f3 f4 f5];
[/code]
Solver stopped prematurely.

fsolve stopped because it exceeded the function evaluation limit,
options.MaxFunEvals = 1000 (the selected value).


X =

   18.7895   19.0894   19.0963   19.1094  -46.0868


FVAL =

   -0.0022   -0.0180   -0.0172   -0.0175    2.7252


EXITFLAG =

     0


OUTPUT =

       iterations: 180
        funcCount: 1001
        algorithm: 'trust-region dogleg'
    firstorderopt: 0.0022
          message: [1x143 char]

» 本帖已获得的红花(最新10朵)

The more you learn, the more you know, the more you know, and the more you forget. The more you forget, the less you know. So why bother to learn.
2楼2012-02-22 19:55:48
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

dbb627

荣誉版主 (著名写手)

sunjiahuan: 回帖置顶 2012-02-23 12:12:37
臭水沟(金币+2): 谢谢交流~~ 2012-02-23 18:04:20
CODE:
function [r,n]=mulNewton(F,x0,eps)
if nargin==2
    eps=1.0e-6;
end
x0 = transpose(x0);
Fx = subs(F,findsym(F),x0);
var = sym(symvar(findsym(F)));%var is string 要变换下
dF = jacobian(F,var);
dFx = subs(dF,findsym(dF),x0);
r=x0-inv(dFx)*Fx;
n=1;
tol=1;
while tol>eps
    x0=r;
    Fx = subs(F,findsym(F),x0);
    dFx = subs(dF,findsym(dF),x0);
    r=x0-inv(dFx)*Fx;                                 %核心迭代公式
    tol=norm(r-x0);
    n=n+1;
    if(n>1000)                                              %迭代步数控制
        disp('迭代步数太多,可能不收敛!');
        return;
    end
end

存为.m文件
命令窗口
>> syms x1 x2 x3 x4 x5
>> F=[x1+x2+x3+x4+x5-30;
4.1495*(0.7986-lambertw(2.4534e-007*exp((330.7*x1+354.3091)/443.6719)))-x1/331.0230+1.019e-6*(exp(-x1/1.3403)-1)-4.1495*(0.7986-lambertw(2.4533e-007*exp((326.4292*x2+349.7334)/437.9477)))+x2/(0.323+326.4292)-1.019*10^(-6)*(exp(-x2/1.3403)-1);
4.1495*(0.7986-lambertw(2.4534e-007*exp((330.7*x1+354.3091)/443.6719)))-x1/331.0230+1.019e-6*(exp(-x1/1.3403)-1)-4.1495*(0.7985-lambertw(2.4532e-007*exp((315.4524*x3+337.973)/423.2354)))+x3/(0.323+315.4524)-1.019*10^(-6)*(exp(-x3/1.3403)-1);
4.1495*(0.7986-lambertw(2.4534e-007*exp((330.7*x1+354.3091)/443.6719)))-x1/331.0230+1.019e-6*(exp(-x1/1.3403)-1)-4.1495*(0.7985-lambertw( 2.4531e-007*exp((302.844*x4+324.4644)/406.3363)))+x4/(0.323+302.844)-1.019*10^(-6)*(exp(-x4/1.3403)-1);
4.1495*(0.7986-lambertw(2.4534e-007*exp((330.7*x1+354.3091)/443.6719)))-x1/331.0230+1.019e-6*(exp(-x1/1.3403)-1)-1.019*10^(-6)*(exp(x5/1.3403)-1)];
[r,n]=mulNewton(F,[18.7783   0.01   18.1315   18.0062  -2])
Warning: Matrix is singular to working precision.
> In mulNewton at 17

r =

   NaN
   NaN
   NaN
   NaN
   NaN


n =

     2
[r,n]=mulNewton(F,[18.7783   20  18.1315   18.0062  -20])

r =

   20.0741
   20.0739
   20.0728
   20.0718
  -50.2925


n =

     5
The more you learn, the more you know, the more you know, and the more you forget. The more you forget, the less you know. So why bother to learn.
7楼2012-02-23 10:26:26
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

dbb627

荣誉版主 (著名写手)

【答案】应助回帖

ben_ladeng(金币+2): 谢谢应助 2012-02-22 21:58:25
ben_ladeng(专家考核): 2012-02-22 21:59:32
引用回帖:
5楼: Originally posted by sunjiahuan at 2012-02-22 20:53:37:
不好意思,刚看到I1,I2,I3,I4方程中最后一项的里的x1,x2,x3,x4, 应该为-x1,-x2,-x3,-x4,而x5不变。所以我附件里fun.m的方程组里的也要相应改变,因无法编辑,在此说明一下。比如I1中的最后一项1.019*10^(-6)*( ...

CODE:
function aa
[X,FVAL,EXITFLAG,OUTPUT] =fsolve(@fun,[18.7783   0.01   18.1315   18.0062  -2],optimset('MaxFunEvals',1000))
function f=fun(x)
x1=x(1);
x2=x(2);
x3=x(3);
x4=x(4);
x5=x(5);
f1=x1+x2+x3+x4+x5-30;
f2=4.1495*(0.7986-lambertw(2.4534e-007*exp((330.7*x1+354.3091)/443.6719)))-x1/331.0230+1.019e-6*(exp(-x1/1.3403)-1)-4.1495*(0.7986-lambertw(2.4533e-007*exp((326.4292*x2+349.7334)/437.9477)))+x2/(0.323+326.4292)-1.019*10^(-6)*(exp(-x2/1.3403)-1);
f3=4.1495*(0.7986-lambertw(2.4534e-007*exp((330.7*x1+354.3091)/443.6719)))-x1/331.0230+1.019e-6*(exp(-x1/1.3403)-1)-4.1495*(0.7985-lambertw(2.4532e-007*exp((315.4524*x3+337.973)/423.2354)))+x3/(0.323+315.4524)-1.019*10^(-6)*(exp(-x3/1.3403)-1);
f4=4.1495*(0.7986-lambertw(2.4534e-007*exp((330.7*x1+354.3091)/443.6719)))-x1/331.0230+1.019e-6*(exp(-x1/1.3403)-1)-4.1495*(0.7985-lambertw( 2.4531e-007*exp((302.844*x4+324.4644)/406.3363)))+x4/(0.323+302.844)-1.019*10^(-6)*(exp(-x4/1.3403)-1);
f5=4.1495*(0.7986-lambertw(2.4534e-007*exp((330.7*x1+354.3091)/443.6719)))-x1/331.0230+1.019e-6*(exp(-x1/1.3403)-1)-1.019*10^(-6)*(exp(x5/1.3403)-1);
f=[f1 f2 f3 f4 f5];

将上述代码拷到editor里面,存为.m文件,点击editor中run按钮
结果如下
Equation solved.

fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.




X =

   20.0741   20.0739   20.0728   20.0718  -50.2925


FVAL =

  1.0e-007 *

    0.0000   -0.8502   -0.8544   -0.8544   -0.8544


EXITFLAG =

     1


OUTPUT =

       iterations: 13
        funcCount: 74
        algorithm: 'trust-region dogleg'
    firstorderopt: 4.6500e-007
          message: [1x695 char]
The more you learn, the more you know, the more you know, and the more you forget. The more you forget, the less you know. So why bother to learn.
6楼2012-02-22 21:29:51
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

dbb627

荣誉版主 (著名写手)

【答案】应助回帖

sunjiahuan: 回帖置顶 2012-02-23 12:12:31
臭水沟(金币+2): 谢谢交流~~ 2012-02-23 18:04:09
你可以看看我的牛顿法计算结果,出现那样的提示信息,应该就是初值不合适,使得一阶导数矩阵迭代时出现奇异,个别元素出现无穷大
The more you learn, the more you know, the more you know, and the more you forget. The more you forget, the less you know. So why bother to learn.
8楼2012-02-23 10:42:54
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
普通回帖

sunjiahuan

铜虫 (小有名气)

送鲜花一朵
引用回帖:
: Originally posted by dbb627 at 2012-02-22 19:55:48:
错误提示信息是矩阵奇异,
可能初值不太合适
我用自带fsolve解了下
结果不是很好
[/code]
function aa
[X,FVAL,EXITFLAG,OUTPUT] =fsolve(@fun,[18.7783   0.01   18.1315   18.0062  -2],optimset('MaxFun ...

您好,非常感谢你的帮助,您能不能把你的matlab代码发到我的邮箱里么sunjiahuan0370@sina.com?我把你贴出来的代码移到我的matlab里居然没成功。谢谢了。
3楼2012-02-22 20:29:00
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

sunjiahuan

铜虫 (小有名气)

sunjiahuan: 回帖置顶 2012-02-22 20:46:39
不好意思,刚看到I1,I2,I3,I4方程中最后一项的里的x1,x2,x3,x4, 应该为-x1,-x2,-x3,-x4,而x5不变。所以我附件里fun.m的方程组里的也要相应改变,因无法编辑,在此说明一下。比如I1中的最后一项1.019*10^(-6)*(exp(x1/1.3403)-1);应改为1.019*10^(-6)*(exp(-x1/1.3403)-1);
4楼2012-02-22 20:46:34
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

sunjiahuan

铜虫 (小有名气)

引用回帖:
: Originally posted by dbb627 at 2012-02-22 19:55:48:
错误提示信息是矩阵奇异,
可能初值不太合适
我用自带fsolve解了下
结果不是很好
[/code]
function aa
[X,FVAL,EXITFLAG,OUTPUT] =fsolve(@fun,[18.7783   0.01   18.1315   18.0062  -2],optimset('MaxFun ...

不好意思,刚看到I1,I2,I3,I4方程中最后一项的里的x1,x2,x3,x4, 应该为-x1,-x2,-x3,-x4,而x5不变。所以我附件里fun.m的方程组里的也要相应改变,因无法编辑,在此说明一下。比如I1中的最后一项1.019*10^(-6)*(exp(x1/1.3403)-1);应改为1.019*10^(-6)*(exp(-x1/1.3403)-1);非常感谢您的帮助。
5楼2012-02-22 20:53:37
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

dingd

铁杆木虫 (职业作家)

【答案】应助回帖

★ ★
xiegangmai: 金币+2, 专家考核, 谢谢参与! 2013-04-17 23:53:43
猜初值很头疼的,下面是正解:

x1: 2.60751007153198
x2: 2.56027779100342
x3: 2.43893790346484
x4: 2.29898071559569
x5: 20.094293518415
9楼2013-04-17 10:28:38
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

cooooldog

铁杆木虫 (著名写手)

ส็็็

【答案】应助回帖

引用回帖:
8楼: Originally posted by dbb627 at 2012-02-23 10:42:54
你可以看看我的牛顿法计算结果,出现那样的提示信息,应该就是初值不合适,使得一阶导数矩阵迭代时出现奇异,个别元素出现无穷大

迭代中雅克比奇异很正常,增加一个dumping 因子就可以了
就是每次迭代的时候, 给雅克比矩阵加上 eye(n)*dumping (dumping 就是一个非0的常数)
ส็็็็็็็็็็็็็็็็็็็็
10楼2013-12-03 10:09:21
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 sunjiahuan 的主题更新
信息提示
请填处理意见