The following code contain the mentioned error . what to do ?

1 次查看(过去 30 天)
n=6;
phi1=0.3;
phi2=0.5;
seta=0.4;
z0=0.6;
s=2;
a=normrnd(0,(s)^2,n,1);
z=zeros(n,1);z0=0.4;z(1)=.3;
z(2)=phi1*z(1)+phi2*z0+a(2)-seta*a(1);
for i=3:n
z(i)=phi1*z(i-1)+phi2*z(i-2)+a(i)-seta*a(i-1);
end
summ=0;syms phi1 phi2 seta
for t=4:n
summ=summ+(z(t)-phi1*z(t-1)-phi2*z(t-2)+seta*a(t-1))^2;
end
L=((-n/2)*log(2*pi)-((n/2)*log(s^2))-((1/(2*s^2))*summ));
K = @(phi1,phi2,seta)(L);
Lfcn = @(b) K(b(1),b(2),b(3));
b0 = [0.3; 0.5; 0.4];
Roots = fsolve(Lfcn, b0)
Error using fsolve (line 269)
FSOLVE requires all values returned by functions to be of
data type double.

采纳的回答

Walter Roberson
Walter Roberson 2016-12-28
Change
K = @(phi1,phi2,seta)(L);
Lfcn = @(b) K(b(1),b(2),b(3));
to
Lfcn = matlabFunction(L,'vars', {[phi1; phi2; seta]});
and change your fsolve call to
options = optimoptions(@fsolve,'MaxFunctionEvaluations', 1800, 'Algorithm', 'levenberg-marquardt');
Roots = fsolve(Lfcn, b0, options)
  2 个评论
mohammed elmenshawy
mohammed elmenshawy 2016-12-29
thank u very very very much . really good answer ,but what does 1800 mean in options
Walter Roberson
Walter Roberson 2016-12-29
1800 means allow the function to be executed 1800 times. The function does not converge with the default 500 iterations; it needs more than 1700 iterations to converge.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by