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);

回答(2 个)

Walter Roberson
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.
madhan ravi
madhan ravi 2019-5-11
编辑:madhan ravi 2019-5-11
Last x(5) should be x(4)
Also
.^
.*
./ % to be taken care of

此问题已关闭。

产品

标签

关闭:

2021-8-20

Community Treasure Hunt

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

Start Hunting!

Translated by