index exceeds matrix dimension
Infos
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Afficher commentaires plus anciens
Recently i stumbled across a optimization problem using fminsearch but when i try to execute the code it says-"index exceeds matrix dimension" can someone help me how to solve this error?
f=@(x)( x(4)*(((x(1)^2*10^5*(2+2*0.5) + 2*x(1)*10^5*(1+0.5)*cos(((1+0.5)*pi)/2)+1)))^1/2*(((x(2)^2*10^5*(2+2*0.5)+ x(3)^2*10^10*0.5+ 2*x(2)*10^5*(1+0.5)*cos(((1+0.5)*pi)/2)+ 2*x(3)*10^5*(0.5)*cos((0.5.*pi)/2)+1))^-1/2)-0.0031622*(-10^5*2+108.0248)*((-10^5*2+0.607502)^2+(0.4562*x(5)^2))^-(1/2))^2;
options=optimset('Maxfunevals',10^10,'Maxiter',10^10,'display','final','tolfun',1e-20,'tolx',1e-20);
x=fminsearch(f,[0,-1,-2,-1],options);
Réponses (2)
Walter Roberson
le 11 Mai 2019
0 votes
The code refers to x(5) fairly close to the end, so it needs a vector of 5 or more inputs. The number of inputs constructed by fminsearch is controlled by the length of initial value. You are passing an initial value of length 4 so only 4 values will be passed to your function.
madhan ravi
le 11 Mai 2019
Modifié(e) : madhan ravi
le 11 Mai 2019
Last x(5) should be x(4)
Also
.^
.*
./ % to be taken care of
Cette question est clôturée.
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!