Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Error running fminsearch
Replies: 3   Last Post: Aug 20, 2013 10:20 AM

 Messages: [ Previous | Next ]
 Josef Posts: 2 Registered: 8/15/13
Error running fminsearch
Posted: Aug 15, 2013 5:53 AM

Dear all, can anyone help me with the following error message I am receiving:

Improper assignment with rectangular empty
matrix.

Error in AcAC1 (line 29)
ttc1(1) = min(k(k>=k67));

Error in fminsearch (line 191)
fv(:,1) = funfcn(x,varargin{:});

The point is, that the function works, it only displays the error when trying to minimize it via fminsearch.
The program file is as follows:

function crit=AcAC1(input, options ,comm,coord,l,p,k,S)

k12=input(1);
k23=input(2);
k34=input(3);
k45=input(4);
k67=input(5);
w=l;
q0=input(6);

eq1=w - p*k23 - (1-k23)*q0;

tt1=k(k>k23&k<k34);
g=zeros(1,10000);

for i=1:10000
if (k(i)>k23 & k(i)<k34)
g(i)=S(i);
end
end

bbb=g(g>0);

nnn=length(bbb);

ttc1=zeros(1,nnn);

if k67<1
ttc1(1) = min(k(k>=k67));
index1 = find(k>=ttc1(1)&k<ttc1(1)+0.000001);
else
ttc1(1)=1;
index1=9999;
end

ccc=zeros(1,nnn);
ddd=zeros(1,nnn);
sss=zeros(1,(10000-index1));
vvv=zeros(1,(10000-index1));

ccc(1)=bbb(1)*(1-tt1(1))*0.5;
ddd(1)=ccc(1);
sss(1)=S(index1);
vvv(1)=sss(1);

for i=2:nnn
ccc(i)=bbb(i)*(1-tt1(i))*0.5;
ddd(i)=ccc(i)+ddd(i-1);
end

for i=2:(10000-index1)
sss(i)=S(index1 + i-1);
vvv(i)=sss(i)+vvv(i-1);
end

i=1;
j=1;
while (i<=nnn-1)
if j<10000-index1
if ddd(i)>vvv(j)
j=j+1;
elseif ddd(i)<vvv(j)
ttc1(i+1)=k(index1) +j*0.0001;
i=i+1;
end
else
ttc1(i+1)=1.2;
i=i+1;
end
end

q=zeros(1,nnn);
q(1)=q0;

for i=1:(nnn-1)
q(i+1)=q(i)-p*(1-ttc1(i))/(10000*(1-tt1(i+1))*(1-tt1(i)));
end

eq2=q(nnn);

eq3=p*k45 - coord - w;

eq4=2*p*k67 - coord - w - 2*p*(k67 - k23)/(1-k23) + comm + q0;

eq5=k45-k34 - k23 + k12;

eq6=ttc1(nnn)-1;

input

crit=(abs(eq1)+abs(eq2)+abs(eq3)+abs(eq4) + abs(eq5) + abs(eq6));

And the call file is:

clear all
clc

format long

y=zeros(1,10000);
for i=1:10000
y(i)=i*(10/10000);
end;

k=y/10;

S=lognpdf(y,1,0.6);
zu=sum(S)/1000;
S=S/zu;
b=S.*k;
bm=mean(b)

S1=lognpdf(y,1.0240581,1);
zu1=sum(S1)/1000;
S1=S1/zu1;
b1=S1.*k;
bm1=mean(b1)

bm-bm1

plot(y,S,y,S1)

comm=0.3;
coord=0.5;
l=0.4;
p=2;

options=optimset('Display','iter');

input=[0.3 0.4 0.6 0.8 0.9 0.2];
counter = 1;

test=AcAC1(input, options ,comm,coord,l,p,k,S)

while counter < 8
[output] = fminsearch(@AcAC1input, options ,comm,coord,l,p,k,S);
error=max(abs(output-input));
input=output;
counter=counter +1;
end

Any help is much appreciated

Date Subject Author
8/15/13 Josef
8/15/13 Torsten
8/16/13 Josef
8/20/13 Torsten