Why isn't this solve working?

조회 수: 4 (최근 30일)
Joshua D'Agostino
Joshua D'Agostino 2015년 1월 20일
댓글: Star Strider 2015년 1월 20일
I'm trying to get out 2 values for an angle, gamma:
gamma = asin((sqrt(1 + d^2)*sin(a))/r)
is the formula for the angle. I understand that asin simply returns the principle value, and so if I want to get out 2 values I's have to solve sin(gamma) = ... etc.
I just can't get it to work. Here's my code:
syms gamma
r = 0.3584;
d = 0.6342;
l = degtorad(10);
b = degtorad(40);
a = (b - atan(d))^2 + l^2 % just how it's defined; these are all just details anyway
S = solve('sin(gamma) = (sqrt(1 + d^2)*sin(a))/r',gamma)
and here is the output:
Error using solve>processString (line 354)
' sin(gamma) = (sqrt(1 + d^2)*sin(a))/r ' is not a valid expression or equation.
Error in solve>getEqns (line 284)
eqns = processString(eqns, v, vc);
Error in solve (line 160)
[eqns,vars,options] = getEqns(varargin{:});
How is that not a valid expression? I don't know where the problem is.
Thanks in advance for all help!

채택된 답변

Star Strider
Star Strider 2015년 1월 20일
This works (in R2014b) with no other changes in your code (other than my having to define my own deg2rad function):
degtorad = @(x) x.*pi/180;
S = solve(sin(gamma) == (sqrt(1 + d^2)*sin(a))/r,gamma)
producing:
S =
asin(2863908454326725/18014398509481984)
pi - asin(2863908454326725/18014398509481984)
or with:
S = vpa(S)
produces:
S =
0.15965626771650156828855864052742
2.9819363858732916701740847427521
  댓글 수: 2
Joshua D'Agostino
Joshua D'Agostino 2015년 1월 20일
right, I'm just an idiot. Thanks so much!
Star Strider
Star Strider 2015년 1월 20일
My pleasure!
You’re definitely not an idiot! None of us learned MATLAB by osmosis. We all have our share of error messages, crashed code, and logic statements that did exactly the opposite of what we intended. (I do, anyway!) Keep coding, and share your expertise here when you have the opportunity.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by