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?

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 4 Mai 2020

1 Stimme

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 Kommentare

Rohit Tamrakar
Rohit Tamrakar am 4 Mai 2020
Thanks Walter this worked.
I got this as answer.
ans =
47.8960
2.2849
-2.1809
I want the the value of "m" to be selected as 2.28 i.e the smallest positive integer among these three values. What code I have to use for selecting 2.28 value?
min(S(S>0))
Rohit Tamrakar
Rohit Tamrakar am 4 Mai 2020
Thanks Walter :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Mathias Andersen
Mathias Andersen am 4 Mai 2020

1 Stimme

Double(S) will produce a matrix with the solutions.
S.m is not a variable stated anywhere in the script

4 Kommentare

Rohit Tamrakar
Rohit Tamrakar am 4 Mai 2020
How can I get the value for variable "m" ?
Walter Roberson
Walter Roberson am 4 Mai 2020
S is the output of solve(). If two or more variables were being solved for and a single output were given, then S would be a structure with one field for each variable being solved for, and then S.m would exist.
S.m would also be created if 'returnconditions', true is specified.
Mathias Andersen
Mathias Andersen am 4 Mai 2020
Bearbeitet: Mathias Andersen am 4 Mai 2020
S contains the values for m
Walter Roberson
Walter Roberson am 4 Mai 2020
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by