Info

This question is closed. Reopen it to edit or answer.

Is there anyway to slove a trigonometric function in a easier way in MAtlab?

1 view (last 30 days)
I had no experience at all with Matlab. Please forgive me if I make any horrible or stupid mistakes.
I am not asking for whole solutions, just trying to find the right way to solve problems in MatLAb.
Problem in details is below:
Basiclly , I am trying to write a function in Matlab which takes 3 inputs x , y , z which indicate the position where I want to arm to reach or point at.
f_1, f_2, f_3 are the angles as shown in the picture.
L is constant, L = 10
I have the following two equations:
sqrt(x^2 + y^2) = L * cos(f_2) + L * cos(f_2 - f_3) ·········································(1)
z = L * sin(f_2) + L * sin(f_2 - f_3) ····························································(2)
After square the (1) on both side and add to the (2), I can get
x^2 + y^2 + z^2 = 2L^2 + 2L^2 * cos(f_3)·····················································(3)
since x,y,z,L are known, I can easily get cos(f_3), with acos(), i can get f_3.
But when I am substitute the f_3 back into the equations into (1) and (2) to get the f_2.
I found the equation becomes really complicated.
for example, look at equation (2)
z = L * sin(f_2) + L * sin(f_2 - f_3)
after expanding. I got:
z = L * sin(f_2) + L * ( sin(f_2) * cos(f_3) - cos(f_2) * sin(f_3) )·····················(4)
then I substitute cos(f_3) and sin(f_3) into the equation (4), I got:
z = L * sin(f_2) + (x^2 + y^2 + z^2 + 2L^2) * sin(f_2) / 2L - L * cos(f_2) * sin(f_3)
which is way too complicated to finish, since I still need to substitute cos(f_2) with sqrt(1 - sin^2(f_2) ).
I am really sorry for the long paragraph of explanation, I just want to make myself clear.
I just wonder if there are any function in Matlab which are meant to solve problems like this?
Or what is the better way to solve f_2 for this problem?

Answers (1)

Orion
Orion on 13 Oct 2014
Edited: Orion on 13 Oct 2014
Hi,
if you have just one equation with one unknown variable, which seems to be the case at the end, you can use fzero to solve your problem.
you'll have to rewrite your equation in a subfunction like
function sol = func(f_2,L,x,y,z)
sol = L * sin(f_2) + (x^2 + y^2 + z^2 + 2L^2) * sin(f_2) / 2L - L * cos(f_2) * sin(f_3) - z
and then call fzero

Community Treasure Hunt

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

Start Hunting!