Solving trigonometric non-linear equations in MATLAB
Afficher commentaires plus anciens
Hi there, I'm trying to solve some non-linear simultaneous equations with trigonometric functions. They are of the form:
297.5*cos(x) + 489*sin(y) - 740.78 = 0;
297.5*sin(x) - 489*cos(y) + 197 = 0;
%Mapping b(1) = x, b(2) = y
f = @(b) [297.5*cos(b(1)) + 489.5*sin(b(2)) -740.78; 297.5*sin(b(1)) - 489*cos(b(2)) +197];
B0 = rand(2,1)*2*pi;
[B,fv,xf,ops] = fsolve(f, B0);
ps = ['theta'; 'beta'];
fprintf(1, '\n\tParameters:\n')
for k1 = 1:length(B)
fprintf(1, '\t\t%s = % .4f\n', ps(k1,:), B(k1))
end
However, I am not getting any results. MATLAB says that the "last step was ineffective". Does this mean that my system is unsolveable or have I made a mistake in my code?
Thank you in advance!
4 commentaires
Walter Roberson
le 3 Sep 2016
There are (at least) two x solutions per cycle of 2 * Pi, and (at least) two y solutions per cycle of 2 * Pi. If you have the symbolic toolbox then you should be able to get exact solutions (to within the accuracy that "740.78 represents)
AVoyage
le 3 Sep 2016
John D'Errico
le 3 Sep 2016
Walter told you exactly how to solve it, and to do so trivially.
AVoyage
le 4 Sep 2016
Réponse acceptée
Plus de réponses (2)
Sumera Yamin
le 1 Juin 2018
hi john, can you comment on why my code (similar as the original question is not giving me any solution? I will really appreciate any help.
Ld= 0.8194 %constant
calib = @(K,L) [cos(K*L).^2 + Ld*K*sin(K*L).*cos(K*L) - 2.2; cos(K*L).^2 - 0.299; Ld*cos(K*L).^2 + (sin(K*L).*cos(K*L))/K - 0.262];
fun = @(b) calib(b(1),b(2));
initial_val=[2.73, 0.6]; % initial value of K and L respectively
[x,fval,exitflag,output] = fsolve(fun,initial_val)
3 commentaires
Walter Roberson
le 1 Juin 2018
You have three equations in two unknowns. You can solve the first two equations together; when you then substitute the values into the third equation, you will get 0.07334537675 instead of 0, indicating that the three equations are inconsistent with each other.
Sumera Yamin
le 4 Juin 2018
It means if i only used two equations instead of 3, then the solution will be possible?
Torsten
le 4 Juin 2018
A solution for the two equations would be possible, but not for all three.
sanjay kolape
le 9 Août 2020
Modifié(e) : Walter Roberson
le 9 Août 2020
% write code
l1 = 10; % length of first arm
l2 = 10; % length of second arm
X_coordinate = input("Enter value of X coordinate : "); % theta1 values
Y_coordinate = input("Enter value of Y coordinate : "); % theta2 values
x0 = 0; y0 = 0; %coordinate of fixed link
syms theta1 theta2
eqn1 = l1*cos(theta1) + l2*cos(theta1-theta2) == X_coordinate;
eqn2 = l1*sin(theta1) + l2*sin(theta1-theta2) == Y_coordinate;
[theta1, theta2]= solve(eqn1,eqn2,theta1,theta2);
theta1 = theta1(2);
theta2 = theta2(2);
x1 = l1*cos(theta1);
y2=l1*sin(theta1);
X1 = [x0 x1]; Y1= [y0 y1];
X2 = [x1 X_coordinate]; Y2 = [y1 Y_coordinate];
comet(X1,Y1);
hold on
comet(X2,Y2);
1 commentaire
Walter Roberson
le 9 Août 2020
It is not clear how this code answers the original Question ?
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!