Error using sym/subsref

조회 수: 1 (최근 30일)
Rohit Tamrakar
Rohit Tamrakar 2020년 5월 4일
댓글: Rohit Tamrakar 2020년 5월 4일
I have this program to get the value of "m"
clc
syms m
eqns = (72*m^2)-(1.5*m^3) == 358;
S=solve (eqns,m,'Real',true)
double (S.m);
However in the output I get this error
S =
32*cos(atan(2167511^(1/2)/5965)/3) + 16
16*3^(1/2)*sin(atan(2167511^(1/2)/5965)/3) - 16*cos(atan(2167511^(1/2)/5965)/3) + 16
16 - 16*3^(1/2)*sin(atan(2167511^(1/2)/5965)/3) - 16*cos(atan(2167511^(1/2)/5965)/3)
Error using sym/subsref
Too many output arguments.
Error in Untitled (line 5)
double (S.m);
Can any body help me with this?

채택된 답변

Walter Roberson
Walter Roberson 2020년 5월 4일
When there is only a single variable being solved for, and ReturnConditions is not set, then solve() does not return a structure containing the one variable: it returns the value of the variable. In terms of your code, that means you would use
double(S) %instead of double(S.m)
Or you could instead
S=solve (eqns, m, 'Real', true, 'returnconditions', true);
and then S.m would exist.
  댓글 수: 3
Walter Roberson
Walter Roberson 2020년 5월 4일
Rohit Tamrakar
Rohit Tamrakar 2020년 5월 4일
Thanks Walter :)

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

추가 답변 (1개)

Mathias Andersen
Mathias Andersen 2020년 5월 4일
Double(S) will produce a matrix with the solutions.
S.m is not a variable stated anywhere in the script
  댓글 수: 4
Mathias Andersen
Mathias Andersen 2020년 5월 4일
편집: Mathias Andersen 2020년 5월 4일
S contains the values for m
Walter Roberson
Walter Roberson 2020년 5월 4일
Not when you solve for a single variable and you do not have ReturnConditions true: in that case, MATLAB cannot tell that apart from the case where you want the non-struct version of the solution.

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

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by