Solve Equation numerically for variable

조회 수: 1 (최근 30일)
Philip Hoskinson
Philip Hoskinson 2016년 7월 21일
댓글: Star Strider 2016년 7월 21일
Need to solve this problem for w:
0 = A + Bcos(w) + Ccos(w) ( A,B,C Constants)
Bounds should be 0-180 for this problem I believe, two solutions possible?

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 7월 21일
solve('A + B*cos(w) + C*cos(w)')
  댓글 수: 2
Philip Hoskinson
Philip Hoskinson 2016년 7월 21일
The following error occurred converting from sym to double: Error using symengine (line 59) DOUBLE cannot convert the input expression into a double array. If the input expression contains a symbolic variable, use VPA.
Error in Post_Final (line 40) HourAngleSunrise_Degrees(i) = rad2deg* solve('A + B*cos(w)+C*sin(w)')
A, B, C are values calculated from matrixes, so A = sin(matrix(i)) etc
Philip Hoskinson
Philip Hoskinson 2016년 7월 21일
Original question had an error that makes this more complicated: Actual equation:
0 = A + Bcos(w) + *Csin(w)*
or with identity:
0 = A = Bcos(w) + Csqrt(1-cos^2(w))

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


Star Strider
Star Strider 2016년 7월 21일
If ‘A’, ‘B’ and ‘C’ are matrices, then:
w = acos(-(B+C)\A);
assuming that the matrices have the appropriate dimensions, and the resulting argument matrix ‘(-(B+C)\A)’ elements are all between -1 and +1.
  댓글 수: 2
Philip Hoskinson
Philip Hoskinson 2016년 7월 21일
Original question had an error that makes this more complicated: Actual equation:
0 = A + Bcos(w) + *Csin(w)*
or with identity:
0 = A = Bcos(w) + Csqrt(1-cos^2(w))
Star Strider
Star Strider 2016년 7월 21일
The Symbolic Math Toolbox comes up with these solutions for ‘w’ that would also work for matrices:
syms A B C w
w_sol = solve(A == B*cos(w) + C*sin(w), w);
w_sol = simplify(w_sol, 'steps',10)
-log((A + (A^2 - B^2 - C^2)^(1/2))/(B - C*1i))*1i
-log((A - (A^2 - B^2 - C^2)^(1/2))/(B - C*1i))*1i
Use the sqrtm and logm functions. Also see the funm function. If you know that your matrices will always be real or positive, you can tell the Symbolic Math Toolbox to assume that. It may simplify the result.

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

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by