The following code contain the mentioned error . what to do ?
2 views (last 30 days)
Show older comments
mohammed elmenshawy
on 28 Dec 2016
Commented: Walter Roberson
on 29 Dec 2016
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.
0 Comments
Accepted Answer
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
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.
More Answers (0)
See Also
Categories
Find more on Communications Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!