马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
方程通式见M文件
m文件:'myfun'
初值:x0=[-2.4887 0.4162 -0.0202]
答案:x=[-2.3693 0.3845 -0.0181]
=================================
function F = myfun(x,d,p)
d=[0.5 1 2 4 6 8];
p=[0.0103 0.0402 0.1538 0.2806 0.3771 0.1381];
F(1)=(exp(-x(3)*d(1)^3-x(2)*d(1)^2-x(1)*d(1))*d(1)+ ...
exp(-x(3)*d(2)^3-x(2)*d(2)^2-x(1)*d(2))*d(2)+ ...
exp(-x(3)*d(3)^3-x(2)*d(3)^2-x(1)*d(3))*d(3)+ ...
exp(-x(3)*d(4)^3-x(2)*d(4)^2-x(1)*d(4))*d(4)+ ...
exp(-x(3)*d(5)^3-x(2)*d(5)^2-x(1)*d(5))*d(5)+ ...
exp(-x(3)*d(6)^3-x(2)*d(6)^2-x(1)*d(6))*d(6))/ ...
(exp(-x(3)*d(1)^3-x(2)*d(1)^2-x(1)*d(1))+ ...
exp(-x(3)*d(2)^3-x(2)*d(2)^2-x(1)*d(2))+ ...
exp(-x(3)*d(3)^3-x(2)*d(3)^2-x(1)*d(3))+ ...
exp(-x(3)*d(4)^3-x(2)*d(4)^2-x(1)*d(4))+ ...
exp(-x(3)*d(5)^3-x(2)*d(5)^2-x(1)*d(5))+ ...
exp(-x(3)*d(6)^3-x(2)*d(6)^2-x(1)*d(6)))-sum(p.*d);
F(2)=(exp(-x(3)*d(1)^3-x(2)*d(1)^2-x(1)*d(1))*d(1)^2+ ...
exp(-x(3)*d(2)^3-x(2)*d(2)^2-x(1)*d(2))*d(2)^2+ ...
exp(-x(3)*d(3)^3-x(2)*d(3)^2-x(1)*d(3))*d(3)^2+ ...
exp(-x(3)*d(4)^3-x(2)*d(4)^2-x(1)*d(4))*d(4)^2+ ...
exp(-x(3)*d(5)^3-x(2)*d(5)^2-x(1)*d(5))*d(5)^2+ ...
exp(-x(3)*d(6)^3-x(2)*d(6)^2-x(1)*d(6))*d(6)^2)/ ...
(exp(-x(3)*d(1)^3-x(2)*d(1)^2-x(1)*d(1))+ ...
exp(-x(3)*d(2)^3-x(2)*d(2)^2-x(1)*d(2))+ ...
exp(-x(3)*d(3)^3-x(2)*d(3)^2-x(1)*d(3))+ ...
exp(-x(3)*d(4)^3-x(2)*d(4)^2-x(1)*d(4))+ ...
exp(-x(3)*d(5)^3-x(2)*d(5)^2-x(1)*d(5))+ ...
exp(-x(3)*d(6)^3-x(2)*d(6)^2-x(1)*d(6)))-sum(p.*d.^2);
F(3)=(exp(-x(3)*d(1)^3-x(2)*d(1)^2-x(1)*d(1))*d(1)^3+ ...
exp(-x(3)*d(2)^3-x(2)*d(2)^2-x(1)*d(2))*d(2)^3+ ...
exp(-x(3)*d(3)^3-x(2)*d(3)^2-x(1)*d(3))*d(3)^3+ ...
exp(-x(3)*d(4)^3-x(2)*d(4)^2-x(1)*d(4))*d(4)^3+ ...
exp(-x(3)*d(5)^3-x(2)*d(5)^2-x(1)*d(5))*d(5)^3+ ...
exp(-x(3)*d(6)^3-x(2)*d(6)^2-x(1)*d(6))*d(6)^3)/ ...
(exp(-x(3)*d(1)^3-x(2)*d(1)^2-x(1)*d(1))+ ...
exp(-x(3)*d(2)^3-x(2)*d(2)^2-x(1)*d(2))+ ...
exp(-x(3)*d(3)^3-x(2)*d(3)^2-x(1)*d(3))+ ...
exp(-x(3)*d(4)^3-x(2)*d(4)^2-x(1)*d(4))+ ...
exp(-x(3)*d(5)^3-x(2)*d(5)^2-x(1)*d(5))+ ...
exp(-x(3)*d(6)^3-x(2)*d(6)^2-x(1)*d(6)))-sum(p.*d.^3);
=====================================================
执行部分:
x0=[-2.4887 0.4162 -0.0202];
options=optimset('Display','iter');
[x,favl,exitflag]=fsolve(@myfun,x0,options)
=====================================================
结果:
Optimization terminated: first-order optimality is less than options.TolFun.
x =
-1.4799 0.1720 -0.0034
favl =
1.0e-012 *
-0.0044 -0.0462 -0.4832
exitflag =
1
==============================================
不知错在哪里,是否迭代步长或精度没设置好 |