Clear Filters
Clear Filters

How do I solve this set of equations using MATLAB?

1 view (last 30 days)
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?

Answers (2)

Torsten
Torsten on 8 Nov 2022
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 Comments
John D'Errico
John D'Errico on 8 Nov 2022
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 on 8 Nov 2022
And this is the case somewhere ? The n_i are all outside the trig expressions.

Sign in to comment.


Torsten
Torsten on 8 Nov 2022
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 = 

Community Treasure Hunt

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

Start Hunting!