|
本帖最后由 matlab的旋律 于 2015-3-31 20:08 编辑
求解3个方程组成的方程组,这里用到了两种不同的方法.一种是直接使用matlab里面的库函数fsolve(默认为信赖域法),另外一种是求这3个数值为0的符号方程的平方和的最小值方法,用的fminsearch函数.这两种方法都不是全局收敛的,因此对初始点的选取有比较严格的要求.程序如下,使用的matlab版本为2014b.
clear all
close all
clc
format long
%Beta x(1)
%Gamma x(2)
%Eta x(3)
global t Sigma T n
t = [140 140 140 140 242 242 330 330 330 330 492 492];
Sigma = [0 0 0 0 1 1 0 0 0 0 1 1];
T = [55 55 55 55 20 20 -20 -20 -20 -20 20 20];
n = length(t);
x0 = [2.3063;0.1;320.0723];%选取初始值
options = optimoptions('fsolve','Display','iter');
[x,fval] = fsolve(@Func,x0,options)%信赖域法
f = 0;
for k = 1:n
f = f + Sigma(k)*(log(x(1)) + (x(1) - 1)*log(t(k)) + x(2)*T(k) - x(1)*log(x(3))) - ...
(t(k)/x(3))^x(1)*exp(x(2)*T(k));
end
f
function F = Func(x)
global t Sigma T n
f1 = 0;
f2 = 0;
f3 = 0;
for k = 1:n
f1 = f1 + Sigma(k)*(1/x(1) + log(t(k)) - log(x(3))) - (t(k)/x(3))^x(1)*exp(x(2)*T(k))*log(x(1));
f2 = f2 + Sigma(k)*(-x(1)/x(3)) - t(k)^x(1)*exp(x(2)*T(k))*(-x(1))*x(3)^(-x(1) - 1);
f3 = f3 + Sigma(k)*T(k) - (t(k)/x(3))^x(1)*exp(x(2)*T(k))*T(k);
end
F = [f1;f2;f3];
end
%%%%%%%%%%%%%%%%%%下面为fminsearch%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
close all
clc
format long
%Beta x(1)
%Gamma x(2)
%Eta x(3)
global t Sigma T n
t = [140 140 140 140 242 242 330 330 330 330 492 492];
Sigma = [0 0 0 0 1 1 0 0 0 0 1 1];
T = [55 55 55 55 20 20 -20 -20 -20 -20 20 20];
n = length(t);
x0 = [2.3063;0.1;320.0723];%选取初始值
[x,fval] = fminsearch(@Func_1,x0)
f = 0;
for k = 1:n
f = f + Sigma(k)*(log(x(1)) + (x(1) - 1)*log(t(k)) + x(2)*T(k) - x(1)*log(x(3))) - ...
(t(k)/x(3))^x(1)*exp(x(2)*T(k));
end
f
function F = Func(x)
global t Sigma T n
f1 = 0;
f2 = 0;
f3 = 0;
for k = 1:n
f1 = f1 + Sigma(k)*(1/x(1) + log(t(k)) - log(x(3))) - (t(k)/x(3))^x(1)*exp(x(2)*T(k))*log(x(1));
f2 = f2 + Sigma(k)*(-x(1)/x(3)) - t(k)^x(1)*exp(x(2)*T(k))*(-x(1))*x(3)^(-x(1) - 1);
f3 = f3 + Sigma(k)*T(k) - (t(k)/x(3))^x(1)*exp(x(2)*T(k))*T(k);
end
F = f1^2 + f2^2 + f3^2;
end
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|