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
댓글 수: 0
채택된 답변
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.r
sol.theta
sol.conditions
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)
vpa(sol.theta)
And finally, assuming you just want the principle solutions, in double precision...
format long g
double(subs(sol.r,0))
double(subs(sol.theta,0))
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))
sind(sym(120))
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
2022년 9월 21일
편집: John D'Errico
2022년 9월 21일
Walter is certainly correct. I have modified my answer to reflect that.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Number Theory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!