Solving trigonometric non-linear equations in MATLAB
이전 댓글 표시
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
Walter Roberson
2016년 9월 3일
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
2016년 9월 3일
John D'Errico
2016년 9월 3일
Walter told you exactly how to solve it, and to do so trivially.
AVoyage
2016년 9월 4일
채택된 답변
추가 답변 (2개)
Sumera Yamin
2018년 6월 1일
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
Walter Roberson
2018년 6월 1일
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
2018년 6월 4일
It means if i only used two equations instead of 3, then the solution will be possible?
Torsten
2018년 6월 4일
A solution for the two equations would be possible, but not for all three.
sanjay kolape
2020년 8월 9일
편집: Walter Roberson
2020년 8월 9일
% 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
Walter Roberson
2020년 8월 9일
It is not clear how this code answers the original Question ?
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!