How can I solve a system of non-linear equations with complex numbers?

조회 수: 3 (최근 30일)
I'm in Mechanics of Machinery and I'm trying to use Matlab to help solve these equations:
eq1 = 0 == 2*cosd(240) + 10*cosd(theta) -r;
eq2 = 0 == 2*1i*sin(120) + 10*1i*sind(theta);
I need to solve for 'r' and 'theta'. I'm not great at coding but solving by hand is out of the question. Any help would be greatly appreciated. Thanks

채택된 답변

John D'Errico
John D'Errico 2022년 9월 21일
편집: John D'Errico 2022년 9월 21일
WHY NOT TRY IT? Assuming you really intended for the second equation to use sind(120)...
syms theta r
eq1 = 0 == 2*cosd(240) + 10*cosd(theta) -r;
eq2 = 0 == 2*1i*sind(120) + 10*1i*sind(theta);
sol = solve(eq1,eq2,'returnconditions',true)
sol = struct with fields:
r: [2×1 sym] theta: [2×1 sym] parameters: k conditions: [2×1 sym]
sol.r
ans = 
sol.theta
ans = 
sol.conditions
ans = 
So k is any integer. There are of course infinitely many solutions, though the primary solutions happen at k=0. If you want actual numbers...
vpa(sol.r)
ans = 
vpa(sol.theta)
ans = 
And finally, assuming you just want the principle solutions, in double precision...
format long g
double(subs(sol.r,0))
ans = 2×1
8.8488578017961 -10.8488578017961
double(subs(sol.theta,0))
ans = 2×1
-9.97422179440135 189.974221794401
Not that difficult to solve by hand, but this was really pretty easy. How would you solve it by hand?
First, recognize that these have simple numerical values.
cosd(sym(240))
ans = 
sind(sym(120))
ans = 
So now we can write the two equations with those numbers substituted.
0 == 2*(-1/2) + 10*cosd(theta) - r
0 == 2*1i*sqrt(3)/2 + 10*1i*sind(theta)
I'll also solve directly for r, since r appears in only one place. And in the second equation, get rid of the imaginary multiplier, as it appears on both terms.
r == -1 + 10*cosd(theta)
0 == sqrt(3) + 10*sind(theta)
Already, that is getting pretty simple. We might wish to solve for theta from the second equation now, as:
theta = asind(-sqrt(3)/10)
but that is only one of the two primary solutions. If we wish to write all solutions, we would quickly arrive at the same result given by solve.
  댓글 수: 3
John D'Errico
John D'Errico 2022년 9월 21일
편집: John D'Errico 2022년 9월 21일
Walter is certainly correct. I have modified my answer to reflect that.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by