The following code contain the mentioned error . what to do ?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
mohammed elmenshawy
el 28 de Dic. de 2016
Comentada: Walter Roberson
el 29 de Dic. de 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 comentarios
Respuesta aceptada
Walter Roberson
el 28 de Dic. de 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 comentarios
Walter Roberson
el 29 de Dic. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Communications Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!