24小时热门版块排行榜    

查看: 4656  |  回复: 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的回帖
回帖置顶 ( 共有3个 )

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的回帖

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

荣誉版主 (著名写手)

【答案】应助回帖

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的回帖
回帖支持 ( 显示支持度最高的前 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

荣誉版主 (著名写手)

【答案】应助回帖

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的回帖
普通回帖

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

铜虫 (小有名气)

引用回帖:
: 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 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 欢迎发来filecode的Mz6后的代码验证其规律 +55 医学老男孩 2026-08-13 123/6150 2026-08-19 23:44 by stan_et
[基金申请] 今天基金会出结果吗?20260819 +13 kkkl_v 2026-08-19 13/650 2026-08-19 22:37 by 宝贝虫子
[基金申请] filecode,4个jtjc了 +11 ziyangfang 2026-08-19 13/650 2026-08-19 21:28 by aasahr
[教师之家] 为什么余额宝的年化利率越来越低?主要原因有哪些? +5 瞬息宇宙 2026-08-15 5/250 2026-08-19 20:23 by super2002521
[基金申请] 今天放榜没戏了吧 +4 yuleib84 2026-08-19 5/250 2026-08-19 19:52 by hhs666
[基金申请] 今天放榜吗? +14 布布和一二 2026-08-19 15/750 2026-08-19 18:07 by gltch
[基金申请] filecode=后面第一个是大写字母 +10 wangze12014 2026-08-14 12/600 2026-08-19 16:56 by 苦难博士
[基金申请] 2027广东省杰青 +4 奶牛小黑 2026-08-15 10/500 2026-08-19 11:02 by wanfengnew
[基金申请] 朋友圈看到的 +6 wangzilk 2026-08-18 8/400 2026-08-19 10:55 by Haru815
[基金申请] 快农历七夕节了,轻松一下,男人悄悄话,女施主请不要进来。 +6 Tide man 2026-08-14 7/350 2026-08-19 09:56 by ZJTJZ
[基金申请] 什么时候开奖? +6 CrisMessi 2026-08-18 6/300 2026-08-19 08:06 by Equinoxhua
[基金申请] 重要消息,中午系统在维护 +10 yuleib84 2026-08-18 11/550 2026-08-19 07:30 by 羽毛枫f
[基金申请] 明天放榜? +5 Shxjjxjkx 2026-08-18 5/250 2026-08-18 18:14 by -大大大大大-
[基金申请] 时间戳又变了8-15 +14 archvillain 2026-08-15 26/1300 2026-08-18 13:37 by phantomgost
[基金申请] 今天维护系统维护 祝所有人 高中 +8 gjjjzhong 2026-08-18 9/450 2026-08-18 13:01 by 家与远方
[基金申请] 哪位老哥知道今年的国自然具体哪一天放榜? +13 Ldrop2023 2026-08-13 16/800 2026-08-18 12:25 by 淀粉搬运工
[基金申请] 93BebMhtakh前后11位开头都是大写 +4 且听虎啸 2026-08-17 5/250 2026-08-18 00:49 by 蔡棒棒菂
[基金申请] 感觉是下周放榜了 +6 angus9576 2026-08-17 11/550 2026-08-17 23:57 by angus9576
[基金申请] 今天系统多次维护,明天很可能放榜! +8 zju2000 2026-08-16 9/450 2026-08-17 12:20 by lmz0216
[精细化工] 招聘 金属平磨液,抛光液研发工程师 +3 小天0311 2026-08-14 3/150 2026-08-16 07:31 by H9PLUS
信息提示
请填处理意见