What is error(19) or error(15): out of bound(1)...how to resolve?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

What is error(19) or error(15): out of bound(1)...how to resolve?

Satyaballi
please tell me...m solving an optimization problem with inequality
constraints.  The error m getting while running my code is : "error: x(15):
out of bound 1"

please let me know...what is the error and how to resolve this.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: What is error(19) or error(15): out of bound(1)...how to resolve?

James Sherman
On Sat, Oct 27, 2018 at 4:36 PM Satyaballi <[hidden email]> wrote:
please tell me...m solving an optimization problem with inequality
constraints.  The error m getting while running my code is : "error: x(15):
out of bound 1"

please let me know...what is the error and how to resolve this.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html



Hi Satyaballi,

Out of bounds errors occur when you're trying to access a vector with an index that is larger than its length.  For example,
>> x = zeros(1,10);
>> x(12)
error: x(12): out of bound 10
>>

So, from the error you gave, on line 44 of the g function, the vector x (which has size 1) is trying to be accessed by an index of 15.  Usually in these cases, if I can't figure out why this is happening, I either put a breakpoint at that line and see what the value of the offending vector (or index) or place an if/endif statement to check to see if the size of x is 1 (in this case) since you obviously are assuming that it is longer than that.

Hope this helps,
James Sherman Jr.


Reply | Threaded
Open this post in threaded view
|

Re: What is error(19) or error(15): out of bound(1)...how to resolve?

Satyaballi
Hi
thank you for your reply.  But in my code, I've defined 'x' to be 4x1
matrix.  Where is the problem?

please help me resolve this.

My code is:

*clear all;
format short e;

% global variable declaration for all constants
global P=6000 L=14 E=30e6 Delmax=0.25 G=12e6 Taumax=13.6e3 Sigmax=30e3;

%defining initial values, limiting values, max no.of iterations and
tolerance
x0=[0.5;10;0.5;1];
lb=[0.125; 0.1; 0.01; 0.01];
ub=[inf; inf; 10; 2];
maxiter=1000;
tol=1e-8;

%defining objective function
function obj=f(x)
  obj=1.10471*x(1)^2*x(2)+0.04811*x(3)*x(4)*(14+x(2));
endfunction

%definging gradient of objective function
function gradf=df(x)
 
gradf=[2.20942*x(1)*x(2);1.10471*x(1)^2+0.04811*x(3)*x(4);0.04811*x(4)*(14+x(2));
         0.04811*x(3)*(14+x(2))];
endfunction

%defining Hessian of objective function
function Hessobj=ddf(x)
  Hessobj=[2.20942*x(2) 2.20942*x(1) 0 0;2.20942*x(1) 0 0.04811*x(4)
0.04811*x(3);
           0 0.04811*x(4) 0 0.04811*(14+x(2));0 0.04811*x(3)
0.04811*(14+x(2)) 0];
endfunction

%defining constraints
function ineqcons=g(x)
  global P L E Delmax G Taumax Sigmax;
  %display(Taumax);
  Tau1=P/(sqrt(2)*x(1)*x(2));
  M=P*(L+x(2)/2);
  R=sqrt(x(2)^2/4+((x(1)+x(3))/2)^2);
  J=2*sqrt(2)*x(1)*x(2)*(x(2)^2/12+((x(1)+x(3))/2)^2);
  Tau2=M*R/J;
  Tau=sqrt(Tau1^2+Tau1*M*x(2)/J+Tau2^2);
  Sigma=6*P*L/(x(4)*x(3)^2);
  Delta=4*P*L^3/(E*x(3)^3*x(4));
  Pc=(4.103*E/L^2)*(x(3)*x(4)^3/6)*(1-(x(3)/2*L)*sqrt(E/(4*G)));
  ineqcons=[-(Tau-Taumax); -(Sigma-Sigmax); -(x(1)-x(4)); -(Delta-Delmax);
-(0.10471*x(1)^2+0.04811*x(3)*x(4)(14+x(2))-5); -(P-Pc)];
endfunction

%Supplying Objective function including Gradient and Hessian
Objfun={@(x)f(x),@(x)df(x),@(x)ddf(x)};

[x,obj,info,iter,nf,lambda] = ...*
sqp(x0,Objfun,[],@(x)g(x),lb,ub, maxiter, tol)




--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: What is error(19) or error(15): out of bound(1)...how to resolve?

marco atzeri-2
Am 28.10.2018 um 20:05 schrieb Satyaballi:
> Hi
> thank you for your reply.  But in my code, I've defined 'x' to be 4x1
> matrix.  Where is the problem?
>

>    ineqcons=[-(Tau-Taumax); -(Sigma-Sigmax); -(x(1)-x(4)); -(Delta-Delmax);
> -(0.10471*x(1)^2+0.04811*x(3)*x(4)(14+x(2))-5); -(P-Pc)];
                                     ^ here is the error
probably a space or moltiplication sign is missing


before running the code you should have tested all the functions one,
by one....


---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus