solving equations with trigonometric functions
38 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Harshith Mahesh
le 5 Avr 2021
Commenté : Harshith Mahesh
le 7 Avr 2021
Hi, I have been trying to solve the following equations for the variables theta3 and theta4. So I wrote the code as seen below.
syms x1 x2 x3 x4 x5 x6 theta2 theta3 theta4 Ad Dd
theta2 = 119.92
x1 = 135
x2 = 25
x5 = 120
x6 = 35
Ad = 110.49467458
Dd = 9.5869687
eqn1 = x1*cos(theta2) + x2*sin(theta2) + x5*cos(theta3) -x6*cos(theta4) - Ad == 0
eqn2 = x1*sin(theta2) -x2*cos(theta2) - x5*sin(theta3) -x6*sin(theta4) - Dd ==0
S1 = solve(eqn1,eqn2)
But my output looks like this
S1 =
theta3: [2×1 sym]
theta4: [2×1 sym]
Does anyone know how do I get the answer in degrees?
I'm fairly new to Matlab, so I'm sorry if this an extremely basic question.
Regards, Harshith
4 commentaires
John D'Errico
le 6 Avr 2021
You will need to seriously look at both the equations you have written, as well as the constants, since no real solution exists to the problem you have psosed. See my answer.
Bruno Luong
le 6 Avr 2021
theta2 = 119.92
degree or radian?
Do you know sin/cos argument is radian?
Réponse acceptée
John D'Errico
le 6 Avr 2021
Note that x1, x2, x5, x6 are just NUMBERS. Defining them as syms in advance does nothing. MATLAB is a language with dynamic variable definitions. So if you do this:
syms x
x = 7;
whos x
then x is now a double precision number. You have achieved NOTHING with the syms call. x is not a symbolic version of the number 7.
Now let me look at your code. First, learn to use semi-colons at the end of your lines. That prevents MATLAB from dumping loads of crap to the command window.
syms theta2 theta3 theta4 Ad Dd
theta2 = 119.92;
x1 = 135;
x2 = 25;
x5 = 120;
x6 = 35;
Ad = 110.49467458;
Dd = 9.5869687;
eqn1 = x1*cos(theta2) + x2*sin(theta2) + x5*cos(theta3) -x6*cos(theta4) - Ad == 0;
eqn2 = x1*sin(theta2) -x2*cos(theta2) - x5*sin(theta3) -x6*sin(theta4) - Dd ==0;
So we have two equations in the two unknowns, theta3 & theta4.
Remember though, you used sin and cos. Trig functions in MATLAB use RADIANS, NOT degrees. So your solution will be in radians. If you want degrees, then you want to use the functions sind and cosd. So we really need to re-write your equations in terms of degrees. That seems clear because theta2 is 119.92, which must be a value in degrees, not radians.
eqn1 = x1*cosd(theta2) + x2*sind(theta2) + x5*cosd(theta3) -x6*cosd(theta4) - Ad == 0
eqn2 = x1*sind(theta2) -x2*cosd(theta2) - x5*sind(theta3) -x6*sind(theta4) - Dd ==0
Next, we can use solve. Will this problem have multiple solutions? Of course. We should be able to add integrer multiples of 2*pi radians (or 360 degrees) to any solution.
thetasol = solve(eqn1,eqn2,[theta3,theta4])
thetasol.theta3
thetasol.theta4
Now you convert those solutions to floating point numbers using either vpa or double.
double(thetasol.theta3)
double(thetasol.theta4)
What does that tell me? This says your problem has no solution in real numbers. So if you have the correct values for your problem, then you wrote your equations incorrectly, or vice-versa.
Plus de réponses (2)
J Chen
le 5 Avr 2021
format long % show more digits
double(S1.theta3)
double(S1.theta4)
format % back to the default format
1 commentaire
John D'Errico
le 6 Avr 2021
While this is correct as an answer, the problem itself has some major caveats that would need to be addressed. See my answer for a discussion of the problems.
darova
le 6 Avr 2021
Here is the similar example. Maybe you will be interested
- , , and length are given. angle is changing
- Calculate length and
- Calculate vector
- Rotate by degree, make it of length
See code attached
0 commentaires
Voir également
Catégories
En savoir plus sur Calculus dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!