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

1 Ansicht (letzte 30 Tage)
mohammed elmenshawy am 28 Dez. 2016
Kommentiert: Walter Roberson am 29 Dez. 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 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson am 28 Dez. 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 KommentareKeine anzeigenKeine ausblenden
mohammed elmenshawy am 29 Dez. 2016
thank u very very very much . really good answer ,but what does 1800 mean in options
Walter Roberson am 29 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by