index exceeds matrix dimension
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
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);
댓글 수: 0
답변 (2개)
Walter Roberson
2019년 5월 11일
0 개 추천
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.
댓글 수: 0
madhan ravi
2019년 5월 11일
편집: madhan ravi
2019년 5월 11일
Last x(5) should be x(4)
Also
.^
.*
./ % to be taken care of
댓글 수: 0
이 질문은 마감되었습니다.
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!