# Using Solve Function for range returns error "Assignment has more non-singleton rhs dimensions than non-singleton subscripts"

2 views (last 30 days)
Anthony on 17 Nov 2015
Edited: Walter Roberson on 7 Feb 2019
Hi there,
I'm trying to find a solution set over a range of X,Y,Z for a simple equation. I used nested for loops to run through the X,Y,Z and the solve function and on the second step through I get the error "Assignment has more non-singleton rhs dimensions than non-singleton subscripts" I've been reading through other posts and do not understand where this error is coming from.
This is my code snippet:
a = 100;
b = 50;
X = 0:.1:10;
Y = 0:.1:10;
Z = 0:.1:10;
for i = 1:length(X)
for j = 1:length(Y)
for k = 1:length(Z)
syms L
PHI = X(i)/(1+L) + (Y(j)+Z(k))/((b/a)^2+L)==0;
Lsol(i,j,k) = solve(PHI,L);
end
end
end
and the full error is :
Error using subsasgn
Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Error in sym/privsubsasgn (line 997)
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
Error in sym/subsasgn (line 834)
C = privsubsasgn(L,R,inds{:});
I didn't know if anyone else has run into this problem before but it seems like there is something simple that I am missing here.
Thanks,
Anthony
Anthony on 17 Nov 2015
I have found the error, you cannot have 0 be a solution to this.

Anthony on 17 Nov 2015
A 0 solution for the first iteration results in the error.
##### 2 CommentsShowHide 1 older comment
Walter Roberson on 7 Feb 2019
Edited: Walter Roberson on 7 Feb 2019
when X is 0 the first term of the addition vanishes and you get more answers than you expect . When Y and Z are both 0 the second term vanishes and you get more answers than you expect . When they are all 0 then both terms vanish and every L is a solution .
The work around is to start all three variable with nonzero values.
Any time you have nonlinear equationss you should worry that there might be more solutions than you expect or that there might be no solutions. It is best not to assign the result of solve directly into a matrix. Assign to a temporary variable and test the size of the result and figure out what you want to do with no solutions or multiple solutions .