필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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
Anthony 2015년 11월 17일
A 0 solution for the first iteration results in the error.
  댓글 수: 2
SHARAD KUMAR UPADHYAY
SHARAD KUMAR UPADHYAY 2019년 2월 7일
"A 0 solution for the first iteration results in the error." what does it mean, i couldnot understand it how to solve. If possible please write the correct programm as asked above.
Walter Roberson
Walter Roberson 2019년 2월 7일
편집: Walter Roberson 2019년 2월 7일
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 .

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by