How to get values of unknowns in the terms of one variable?
2 views (last 30 days)
Show older comments
25*cos(q)+80*cos(s3)-100*cos(s4)-100=0
25*sin(q)+80*sin(s3)-100*sin(s4)-60=0
25*cos(q)+80*cos(s3)+100*cos(s5)-s6=0
25*sin(q)+80*sin(s3)+100*sin(s5)-60=0
I need to write all s's in the terms of q's.
How could İ do it?
0 Comments
Answers (1)
Peter Jarosi
on 26 Jul 2019
Edited: Peter Jarosi
on 26 Jul 2019
I recommend using fsolve() function.
First of all, you cannot express your s's in explicit form but you can solve your non-linear equation system in the following way:
The first step is to write a function which contains your equations and save it with name myEquations.m:
function F = myEquations( s_vector )
global q;
s3 = s_vector(1);
s4 = s_vector(2);
s5 = s_vector(3);
s6 = s_vector(4);
F = zeros(1, 4);
F(1) = 25*cos(q)+80*cos(s3)-100*cos(s4)-100;
F(2) = 25*sin(q)+80*sin(s3)-100*sin(s4)-60;
F(3) = 25*cos(q)+80*cos(s3)+100*cos(s5)-s6;
F(4) = 25*sin(q)+80*sin(s3)+100*sin(s5)-60;
Secondly, your script, which calls the function looks like the following:
global q;
q = 1/2; % It's just an example of your parameter q
s_vector_0 = zeros(1, 4); % Initial values for your unknowns
s_vector = fsolve(@myEquations, s_vector_0);
s3 = s_vector(1);
s4 = s_vector(2);
s5 = s_vector(3);
s6 = s_vector(4);
Your result is an approximation, so you can play with different options of fsolve:
Since your equation system is non-linear, your result can highly depend on initial values of unknowns. I set them to zeros but you can try other initial values, for instance:
s_vector_0 = [2, 1.5, 4, -1]
and check whether your result has been changed or not.
IMPORTANT NOTE (A second version of using fsolve function):
You can combine all of these staffs into one function, and it is better, because this way we can avoid to use global variables (it's highly recommended not to use global variables).
function [s3, s4, s5, s6] = getssfromq(q, s_vector_0)
function F = myEquations( s_vector )
s3 = s_vector(1);
s4 = s_vector(2);
s5 = s_vector(3);
s6 = s_vector(4);
F = zeros(1, 4);
F(1) = 25*cos(q)+80*cos(s3)-100*cos(s4)-100;
F(2) = 25*sin(q)+80*sin(s3)-100*sin(s4)-60;
F(3) = 25*cos(q)+80*cos(s3)+100*cos(s5)-s6;
F(4) = 25*sin(q)+80*sin(s3)+100*sin(s5)-60;
end
s_vector = fsolve(@myEquations, s_vector_0);
s3 = s_vector(1);
s4 = s_vector(2);
s5 = s_vector(3);
s6 = s_vector(4);
end
For this second function your script will be the following:
% Equvivalent with the previous exapmle
q = 1/2;
s_vector_0 = zeros(1, 4);
[s3, s4, s5, s6] = getssfromq(q, s_vector_0);
% You can try other q values, for instance:
q = 6.4;
[s3_new, s4_new, s5_new, s6_new] = getssfromq(q, s_vector_0);
Please let me know which version you like, first or second.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!