Does MATLAB have a way to solve for a variable in a nonlinear equation? (i.e. cos(x) + sin(y), solve for y in terms of x using symbols)

3 vues (au cours des 30 derniers jours)
I have a very long, complicated equation in which is a variable for which I need solved. Basically, what I did was take the typical rotation matrix form and turn it in to a series of nonlinear equations.
xb = xa*(cosd(b)*cosd(c))+ya*((cosd(c)*sind(b)*sind(a))+(sind(c)*cosd(a)))+za*((sind(c)*sind(a)-(cosd(c)*sind(b)*cosd(a))));
yb = xa*(-sind(c)*cosd(b))+ya*(cosd(a)*cosd(c)-sind(a)*sind(b)*sind(c))+za*(sind(c)*sind(b)*cosd(a)+cosd(c)*sind(a));
zb = xa*(sind(b))+ya*(-cosd(b)*sind(a))+za*(cosd(a)*cosd(b));
I solved for two of the angles with respect to the other angle and the vector. What i need to do now is solve for the last angle in terms of just the vector.
Does anyone know if MATLAB can solve for a variable in terms of other variables?
Thank you!

Réponses (2)

Matt J
Matt J le 7 Nov 2013
Modifié(e) : Matt J le 7 Nov 2013
If you have the Optimization Toolbox, there is fsolve(), but it is a numerical solver, i.e., the output is always a number.
If you have the Symbolic Toolbox, you can try to get a closed form symbolic expression for the solution using solve(), but a symbolic solution doesn't always exist for a set of equations.
Additionally, as I told you in an earlier thread, the solutions to the equations you've shown are highly non-unique.
  11 commentaires
Matt J
Matt J le 8 Nov 2013
Modifié(e) : Matt J le 8 Nov 2013
Now I just need to solve for b.
I suspect you will not be able to solve for b. Again, because the solution is non-unique, there have to be some free variables left over. Think of trying to solve the single equation
x+y=1
for both x and y. I'm impressed that the solver took you as far as this, actually.
Walter Roberson
Walter Roberson le 8 Nov 2013
Make sure that n, p, q, r, x, y, z, a, b, c, are all defined as symbols and not functions or arrays. You might want to check with size()

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 7 Nov 2013
In general you can solve some kinds of equations using the Symbolic Toolbox if you have it (it is part of the Student Version license.)
I suggest you see previous discussions about rotation matrices, such as http://www.mathworks.co.uk/matlabcentral/answers/15411-recover-basic-rotations
  1 commentaire
Caraline
Caraline le 7 Nov 2013
Thank you! I will check out these threads. I have used solve, but it doesn't seem to work for arguments of type "sym" with trigonometric functions.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by