Undefined function 'bsxfun' for input arguments of type 'sym'.

Trying to run the following code. I apologize for the length of the question, but my knowledge of MATLAB is very basic, and I want to make sure I provide all needed information:
meanvr = [.56552 0.195165 2.835 .5500];
vrhi = [.861332 0.250000 3.000 .41844];
vrlo = [.405612 0.175165 2.755 .37063];
syms AS JS Fe Pf
Svr = [AS JS Fe Pf];
mx = [0, JS*Fe*Pf;
JS, AS];
reps=500;
rand('state',sum(100*clock));
numvrs = length(meanvr);
allvrs = rand(reps,numvrs);
allvrs = allvrs.*repmat(vrhi-vrlo,reps,1) + repmat(vrlo,reps,1);
for rr = 1:reps
disp(rr);
realmx=subs(mx,Svr,allvrs(rr,:));
[lambdas,lambda1,W,w,V,v]=eigenall(realmx);
sensmx=v*w'/(v'*w);
elastmx=(sensmx.*realmx)/lambda1;
alllams(rr,1)=lambda1;
for xx=1:numvrs
diffofvr=subs(diff(mx,Svr(xx)),Svr,allvrs(rr,:));
vrsens(xx)=sum(sum(sensmx.*diffofvr));
end;
allelasts(rr,:)=((vrsens.*allvrs(rr,:))/lambda1);
end;
realmx=subs(mx,Svr,meanvr);
[lambdas,lambda1,W,w,V,v]=eigenall(realmx);
meanlam1=lambda1; sensmx=v*w'/(v'*w);
elastmx=(sensmx.*realmx)/lambda1;
meansens = zeros(1,numvrs);
for xx = 1: numvrs
diffofvr=subs(diff(mx,Svr(xx)),Svr,meanvr);
meansens(xx) = sum(sum(sensmx.*diffofvr));
end;
meanelast=((meansens.*meanvr)/lambda1);
maxlams=zeros(1,numvrs);
for rate = 1:numvrs
vrates=meanvr; vrates(rate)=vrhi(rate);
realmx=subs(mx,Svr,vrates);
[lambdas,lambda1,W,w,V,v]=eigenall(realmx);
maxlams(rate)=lambda1;
end;
disp(Svr); disp(maxlams)
disp((maxlams-ones(1,numvrs)*meanlam1)/meanlam1)
correls=corrcoef([allvrs,alllams]);
disp(Svr); disp((correls(numvrs+1,1:numvrs)).^2);
disp(Svr); disp(meanelast);
disp(min(double(allelasts))); disp(max(double(allelasts)));
disp(mean(double(allelasts))); disp(std(double(allelasts)));
disp(Svr); CLup=zeros(1,numvrs); CLlo=zeros(1,numvrs);
for vr=1:numvrs
x=sort(allelasts(:,vr));
CLup(vr)=x(1+round((reps-1)*0.975));
CLlo(vr)=x(1+round((reps-1)*0.025));
end
disp(CLup); disp(CLlo);
But I get the following error:
"Undefined function 'bsxfun' for input arguments of type 'sym'.
Error in cov (line 93)
xc = bsxfun(@minus,x,sum(x,1)/m); % Remove mean
Error in corrcoef>correl (line 209)
r = cov(x);
Error in corrcoef (line 92)
r = correl(x);
Error in Thesis92d (line 63)
correls=corrcoef([allvrs,alllams]);"

4 Comments

I think you can make your question more clear and breve
What is your question? The error message clearly tell, that bsxfun cannot be applied for a sym variable. So how can we help then?
Please put your code in a separate font from your text using the
toolbar button.
Hi all,
Thank you very much for your replies so far. I have attempted to format my question so it is more clear. However, as my knowledge of MATLAB is extremely basic, I'm not sure how much code I need to make certain you all have enough information for my problem.
Jan, the trouble is, I'm not sure how to fix the problem. To be frank, though I have read the help manual, I'm still not sure what I need to change in the code.
The code is something I pulled whole from a book (published in 2002), so I'm really not sure why it's not working.

Sign in to comment.

 Accepted Answer

Change
correls=corrcoef([allvrs,alllams]);
to
correls = corrcoef([double(allvrs), alllams]);

5 Comments

Hi Walter, thank you very much for your answer. Unfortunately, I'm still getting the exact same error message.
Originally you had
correls=corrcoef([allvrs,alllams]);
which puts allvrs and alllams together into a single argument and passes that one argument to corrcoef. Now you have
correls=corrcoef(double(allvrs),double(alllams));
which passes the two in as different arguments as there is no [] around the pair of variables.
Your allvrs is a 2D array, reps by numvars. Your alllamns is not initialized, so it is incrementally grown in the "for r" loop, by the statement
alllams(rr,1)=lambda1;
which is going to be creating a column vector. The maximum for rr is going to be reps. So allvars and alllams have the same number of rows, but different number of columns, and when you pass in two parameters to corrcoef() the two need to be exactly the same size. Perhaps you do still want to splice the two together. Perhaps
correls = corrcoef(double([allvrs, alllams]));
Aha! That finally did it. Thank you very, very much!
Of course, now I'm getting a different error message... not sure if I should put this as its own new question, but here it is:
Undefined function 'min' for input arguments of type 'sym'.
Error in Thesis92d (line 74)
disp(min(allelasts)); disp(max(allelasts));
Not to mention that I'm getting non-integer answers for all my lambda values...
At this time of night my eyes seem to be missing that line in your code.
You could try
disp(min(double(allelasts))); disp(max(double(allelasts)));
Yeah, that's probably because it wasn't in there. But yet again, your suggestion fixed it.
Thank you so, so much for your help. It's removed a huge bundle of stress from my shoulders. I am still having problems with getting non-random integers as answers, but I'm going to look at my code for a while longer, and then ask a whole new question if I can't figure out. :)

Sign in to comment.

More Answers (0)

Categories

Asked:

on 26 Sep 2013

Commented:

on 14 Oct 2013

Community Treasure Hunt

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

Start Hunting!