声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1565|回复: 5

[编程技巧] 牛顿法求解非线性方程

[复制链接]
发表于 2009-5-5 09:13 | 显示全部楼层 |阅读模式

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

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

x
我编的这个程序运行不出来,老有错!
初值x0=[0 1]

mulsimNewton.m

410 Bytes, 下载次数: 20

牛顿迭代法程序

f.m

111 Bytes, 下载次数: 15

所求非线性方程组

回复
分享到:

使用道具 举报

发表于 2009-5-5 10:17 | 显示全部楼层
建议直接使用编辑贴出代码!
并看下本版规则! 给齐完整格式:出错代码和出错提示!
 楼主| 发表于 2009-5-14 17:30 | 显示全部楼层

回牛顿法求解非线性方程复 楼主 宇宇 牛

function [y,n]=mulsimNewton(F,x0,eps)
if nargin==2, eps=10^-6; end
x0=transpose(x0); Fx=subs(F,findsym(F),x0);
dF=Jacobian(F); c=subs(dF,findsym(dF),x0);
inv(c)
y=x0-Fx*inv(c); n=1; tol=1;
while tol>eps
    x0=y; Fx=subs(F,findsym(F),x0);
    y=x0-inv(c)*Fx; tol=norm(y-x0); n=n+1;
    if (n>10^10), disp('迭代次数大于最大值,可能不收敛'); return; end
end

function y=F(x)
y=[x(1)-0.7*sin(x(1))-0.2*cos(x(2));x(2)-0.7*cos(x(1))+0.2*sin(x(2))];
y=[y(1) y(2)];

这是错误提示
Warning: Function call F invokes inexact match D:\work\f.m.
??? Input argument "x" is undefined.
Error in ==> f at 2
y=[x(1)-0.7*sin(x(1))-0.2*cos(x(2));x(2)-0.7*cos(x(1))+0.2*sin(x(2))];

[ 本帖最后由 ChaChing 于 2009-5-14 21:00 编辑 ]
发表于 2009-5-14 20:58 | 显示全部楼层
个人水平专业有限, 建议楼主先看下
newton raphson算法
http://forum.vibunion.com/forum/ ... ht=Newton%2BRaphson

评分

1

查看全部评分

 楼主| 发表于 2009-5-17 19:34 | 显示全部楼层

回复 地板 ChaChing 的帖子

还是谢谢哦
发表于 2009-5-17 20:55 | 显示全部楼层

可作下修改

function [y,n]=mulsimNewton(x0,eps)
if nargin==1
    eps=10^-6;
end
x0=transpose(x0);
Fx=subs(F,findsym(F),x0);
dF=Jacobian(F);
c=subs(dF,findsym(dF),x0);
y=x0-inv(c)*Fx; n=1; tol=1;
while tol>eps
    x0=y; Fx=subs(F,findsym(F),x0);
    y=x0-inv(c)*Fx; tol=norm(y-x0); n=n+1;
    if (n>10^10), disp('迭代次数大于最大值,可能不收敛'); return; end
end

function y=F(t,s)
syms t s;
y=[t-0.7*sin(t)-0.2*cos(s);s-0.7*cos(t)+0.2*sin(s)];
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-6-3 20:29 , Processed in 0.080146 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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