声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1040|回复: 4

[编程技巧] 请教一个关于求解非线性方程的问题

[复制链接]
发表于 2010-3-30 18:17 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
请问用迭代的方法求解一个非线性方程,但是我的计算结果和别人的文章的计算结果,存在差异,可能会是什么原因,用什么样的方法,比如 牛顿法,割线法等等,才比较合适呢
回复
分享到:

使用道具 举报

发表于 2010-3-30 21:13 | 显示全部楼层
虽然个人水平可能无法协助, 但总认为LZ说清楚具体些, 别人较易帮忙:loveliness:
 楼主| 发表于 2010-3-30 21:57 | 显示全部楼层

就是下面这个方程

function f=myfunc1(x)
g1=16+4.8*i;
p2=pi^2/0.5^2;
f=[cos(x(1)*0.125)+ cos(x(2)*0.125) + cos(x(3)*0.125);
    x(1)*sin((x(1))*0.125) +x(2)*sin(x(2)*0.125)+x(3)*sin(x(3)*0.125);
    x(1)*(x(1)^2+p2)*sin(x(1)*0.125)/(x(1)^2+p2+g1)+ x(2)*(x(2)^2+p2)*sin(x(2)*0.125)/(x(2)^2+p2+g1)+ x(3)*(x(3)^2+p2)*sin(x(3)*0.125)/(x(3)^2+p2+g1)];
用fsolve就是解不开
 楼主| 发表于 2010-3-30 21:59 | 显示全部楼层

例子是这样的

This example solves the system of two equations and two unknowns:
Rewrite the equations in the form F(x) = 0:
Start your search for a solution at x0 = [-5 -5].
First, write a file that computes F, the values of the equations at x.
function F = myfun(x)
F = [2*x(1) - x(2) - exp(-x(1));
      -x(1) + 2*x(2) - exp(-x(2))];
Save this function file as myfun.m somewhere on your MATLAB path. Next, set up the initial point and options and call fsolve:

x0 = [-5; -5];           % Make a starting guess at the solution
options=optimset('Display','iter');   % Option to display output
[x,fval] = fsolve(@myfun,x0,options)  % Call solver
After several iterations, fsolve finds an answer:

                                  Norm of  First-order Trust-region
Iteration Func-count    f(x)        step   optimality       radius
    0        3       23535.6                2.29e+004        1
    1        6       6001.72           1    5.75e+003        1
    2        9       1573.51           1    1.47e+003        1
    3       12       427.226           1          388        1
    4       15       119.763           1          107        1
    5       18       33.5206           1         30.8        1
    6       21       8.35208           1         9.05        1
    7       24       1.21394           1         2.26        1
    8       27      0.016329    0.759511        0.206      2.5
    9       30  3.51575e-006    0.111927      0.00294      2.5
   10       33  1.64763e-013  0.00169132    6.36e-007      2.5

Equation solved.

结果如下
Optimizer appears to be converging to a minimum that is not a root:
Sum of squares of the function values is > sqrt(options.TolFun).
Try again with a new starting point.
初值

4.7300         
   0.2119 - 7.2609i
   3.0767 -24.8515i

要怎么办才好呢

[ 本帖最后由 ChaChing 于 2010-6-13 22:05 编辑 ]
 楼主| 发表于 2010-4-2 17:56 | 显示全部楼层

请教一个关于求解非线性方程解的问题

function f=myfunc(x)
   x2=0.192313- 7.21727*i; x3=3.11169- 24.6207*i;   
  g1=16+4.8*i; Y=31.5; l=1; p2=l^2*(pi^2)/(b^2)
  n31=x^2+p2+g1; n32=x2^2+p2+g1; n33=x3^2+p2+g1;
mf=[cos(x*0.125)                             cos(x2*0.125)                    cos(x3*0.125); ....
    x*sin(x*0.125)                          x2*sin(x2*0.125)                 x3*sin(x3*0.125);...
    x*(x^2+p2)*sin(x*0.125)/n31   x2*(x2^2+p2)*sin(x2*0.125)/n32    x3*(x3^2+p2)*sin(x3*0.125)/n33];
f=det(mf);
若x初值给5.2

newtonRaphson(func,dfunc,3.2,20,10^(-6))
请问如上的一个非线性方程,我用牛顿辛普森算法,得到结果18.1072
但是结果应为19.3032- 0.241585 *i  为什么我就得不到呢
用fsolve得到的17.7500 - 0.4723i

为什么阿

[ 本帖最后由 ChaChing 于 2010-6-13 22:03 编辑 ]
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-22 01:56 , Processed in 0.052900 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表