Error in my code

1 次查看(过去 30 天)
Shin Lin
Shin Lin 2023-4-28
I already try multiple time to solve the error but failed, can someone help me on this?
Parse error: Incorrect use of '=' operator. Assign a value to a variable using '=' and compare values for equality using '=='. Function 'Inverse_kinematics' (#24.201.202), line 4, column 3:
My code as below:
function [theta1d,theta2d,theta3d,theta4d,theta5d,theta6d,theta7d,theta8d,theta9d,theta10d,theta11d,theta12d,theta13d,theta14d] = inverse_kinematics(ad,bd,cd,dd,ed,fd,gd,hd,id,jd,kd,ld,md,nd)
11=1;
12=1;
theta2d= acos((ad^2+bd^2-11^2-12^2)/(2*11*12));
theta1d= atan((bd/ad)-atan((12*sin(theta2d))/(11+12*cos(theta2d))));
21=1;
22=1;
23=1;
theta5d= acos((cd^2+dd^2-21^2-22^2)/(2*21*22));
theta4d= atan((dd/cd)-atan((22*sin(theta5d))/(21+22*cos(theta5d))));
theta3d= acos((ed^2+dd^2-21^2-23^2)/(2*21*23));
31=1;
32=1;
33=1;
theta8d= acos((fd^2+gd^2-31^2-32^2)/(2*31*32));
theta7d= atan((gd/fd)-atan((32*sin(theta8d))/(31+32*cos(theta8d))));
theta6d= acos((hd^2+gd^2-31^2-33^2)/(2*31*33));
41=1;
42=1;
43=1;
theta9d= acos((id^2+jd^2-41^2-42^2)/(2*41*42));
theta10d= atan((jd/id)-atan((42*sin(theta9d))/(41+42*cos(theta9d))));
theta11d= acos((kd^2+jd^2-41^2-43^2)/(2*41*43));
51=1;
52=1;
53=1;
theta12d= acos((ld^2+md^2-51^2-52^2)/(2*51*52));
theta13d= atan((md/ld)-atan((52*sin(theta12d))/(51+52*cos(theta12d))));
theta14d= acos((nd^2+md^2-51^2-53^2)/(2*51*53));
  1 个评论
Dyuman Joshi
Dyuman Joshi 2023-4-28
Why are you assinging a number to another number?

请先登录,再进行评论。

回答(2 个)

Nithin Kumar
Nithin Kumar 2023-4-28
Hi Shin,
I understand that you are facing an issue while using "=" operator. The "Parse error: Incorrect use of '=' operator, assign a value to the variable using '=' operator" occurs when you try to assign a constant to an another constant.
For more information regarding the use of "=" operator, kindly refer Assigning values to a variable.
For more information regarding the equality "==" operator, kindly refer Equality operator.
I hope it helps.

Image Analyst
Image Analyst 2023-4-28
You can't do this:
51=1;
52=1;
53=1;
Fifty one is NOT one, and it makes absolutely no sense to try to send a constant number like 1 into (and replacing) another constant number such as 51. What is your intent there?

类别

Help CenterFile Exchange 中查找有关 Simulink 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by