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

2 views (last 30 days)
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.

Accepted Answer

Walter Roberson
Walter Roberson on 28 Dec 2016
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 Comments
mohammed elmenshawy
mohammed elmenshawy on 29 Dec 2016
thank u very very very much . really good answer ,but what does 1800 mean in options
Walter Roberson
Walter Roberson on 29 Dec 2016
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Communications Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!