How do I solve this set of equations using MATLAB?

1 次查看(过去 30 天)
I am trying to solve the following equations for the variable :
and
for that I wrote the following:
syms M n_1 n_2 n_3 th1 th2 th3
eqns = [M == ( (n_2*cos(th2) - n_3*cos(th3))/(n_2*cos(th2) + n_3*cos(th3)) )*...
( (n_2*cos(th2) + n_1*cos(th1))/(n_2*cos(th2) - n_1*cos(th1)) ) , ...
n_1*sin(th1) == n_2*sin(th2) , n_1*sin(th1) == n_3*sin(th3) ];
S = solve(eqns, [n_2])
But when I run the code I get that:
Empty sym: 0-by-1
What have I done wrong? How do I solve multiple equations?

回答(2 个)

Torsten
Torsten 2022-11-8
You want to solve for one unknown - thus you only need one of the two equations.
If you want to solve for n1, n2 and n3, you have to specify this is the solve command.
But MATLAB cannot find an analytical solution, as you can see below.
syms M n_1 n_2 n_3 th1 th2 th3
eqns = [M == ( (n_2*cos(th2) - n_3*cos(th3))/(n_2*cos(th2) + n_3*cos(th3)) )*...
( (n_2*cos(th2) + n_1*cos(th1))/(n_2*cos(th2) - n_1*cos(th1)) ) , ...
n_1*sin(th1) == n_2*sin(th2) , n_1*sin(th1) == n_3*sin(th3) ];
S = solve(eqns, [n_1,n_2,n_3])
S = struct with fields:
n_1: [0×1 sym] n_2: [0×1 sym] n_3: [0×1 sym]
  5 个评论
John D'Errico
John D'Errico 2022-11-8
I would note there is pretty much never an analytical solution to a problem, where a variable appears both inside and outside of a trig function. Thus anything of the general form x*sin(x) = c, will generally have no algebraic/analytical solution, even if it has a numerical solution.
Torsten
Torsten 2022-11-8
And this is the case somewhere ? The n_i are all outside the trig expressions.

请先登录,再进行评论。


Torsten
Torsten 2022-11-8
As you can see from the below analysis, there is only the solution n_1 = n_2 = n_3 = 0 without conditions on the angles th1, th2 and th3.
syms M n_1 n_2 n_3 th1 th2 th3
f = M *(n_2*cos(th2) + n_3*cos(th3))*(n_2*cos(th2) - n_1*cos(th1)) - (n_2*cos(th2) - n_3*cos(th3))*(n_2*cos(th2) + n_1*cos(th1));
f = subs(f,[n_2 n_3],[n_1*sin(th1)/sin(th2),n_1*sin(th1)/sin(th3)])
f = 
f = simplify(f)
f = 

类别

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