Reference to non-existent field

11 次查看(过去 30 天)
How can I fix this error?
Reference to non-existent field 'th1'.
Error in Phase1 (line 82)
th1(n) = sx.th1;
clear all
close all
clc
% Initial information %
syms x_A y_A x_D y_D L1 L2 L3 L4 L5 L6 L7 w4 alpha4 al5 al7 t
x_A=0;
y_A=0;
x_D=-6;
y_D=450;
L1=0.6;
L2=0.11;
L3=0.21;
L4=0.2;
L5=0.135;
L6=0.365;
L7=0.21;
alpha4=0.9*cos(t);
w04=0;
th04=239.0394;
al5=65;
al7=120;
% x_A=input('Enter the value of x_A: ');
% y_A=input('Enter the value of y_A: ');
% x_D=input('Enter the value of x_D: ');
% y_D=input('Enter the value of y_D: ');
% L1=input('Enter the value of L1: ');
% L2=input('Enter the value of L2: ');
% L3=input('Enter the value of L3: ');
% L4=input('Enter the value of L4: ');
% L5=input('Enter the value of L5: ');
% L6=input('Enter the value of L6: ');
% L7=input('Enter the value of xL7: ');
% alpha4=input('Enter the value of alpha41: ');
% w4i=input('Enter the value of w4i: ');
% th4i=input('Enter the value of th4i: ');
% al5=input('Enter the value of al5: ');
% al7=input('Enter the value of al7: ');
for t_vec = 0:0.1:10;
sz = numel(t_vec);
w4 = int(alpha4,t) + w04;
th4 = int(w4,t) + th04;
alpha4 = subs(alpha4,t,t_vec);
w4 = subs(w4,t,t_vec);
th4 = subs(th4,t,t_vec);
end
% Calculation of thetas %
th1 = zeros(1,sz);
th2 = zeros(1,sz);
th3 = zeros(1,sz);
th6 = zeros(1,sz);
% Calculation of omegas %
w1 = zeros(1,sz);
w2 = zeros(1,sz);
w3 = zeros(1,sz);
w6 = zeros(1,sz);
% Calculation of alphas %
alpha1 = zeros(1,sz);
alpha2 = zeros(1,sz);
alpha3 = zeros(1,sz);
alpha6 = zeros(1,sz);
% Calculation of instant variables %
for n=1:sz
%th0=[170;90;125;70];
%th=fsolve(@myfun,th0);
sx=solve('x_A-x_D+L1*cosd(th1)+L2*cosd(th2)+L3*cosd(th3)=L4*cosd(th4(n))','y_A-y_D+L1*sind(th1)+L2*sind(th2)+L3*sind(th3)=L4*sind(th4(n))','x_A-x_D+L1*cosd(th1)+L5*cosd(th2+al5)+L6*cosd(th6)=L7*cosd(th4(n)+al7)','y_A-y_D+L1*sind(th1)+L5*sind(th2+al5)+L6*sind(th6)=L7*sind(th4(n)+al7)');
th1(n) = sx.th1;
th2(n) = sx.th2;
th3(n) = sx.th3;
th6(n) = sx.th6;
%sx=solve('L1*exp^ith1+L2*exp^ith2+L3*exp^ith3+sqrt((x_A-x_D)^2+(y_D-y_A)^2)*exp^iarctan((y_D-y_A)/(x_D-x_A))=L4*exp^th4(n)','L1*exp^ith1+L5*exp^i(th2+al5)+L6*exp^ith6+sqrt((x_A-x_D)^2+(y_D-y_A)^2)*exp^iarctan((y_D-y_A)/(x_D-x_A))=L7*exp^(th4(n)+al7)');
%th1(n) = sx.th1;
%th2(n) = sx.th2;
%th3(n) = sx.th3;
%th6(n) = sx.th6;
V = inv([L1*sind(th1) L2*sind(th2) L3*sind(th3) 0;L1*cosd(th1) L2*cosd(th2) L3*cosd(th3) 0;L1*sind(th1) L5*sind(th2+al5) 0 L6*sind(th6);L1*cosd(th1) L5*cosd(th2+al5) 0 L6*cosd(th6)])*[L4*w4(n)*sind(th4(n));L4*w4(n)*cosd(th4(n));L7*w4(n)*sind(th4(n)+al7);L7*w4(n)*cosd(th4(n)+al7)];
w1(n)= V(1);
w2(n)= V(2);
w3(n)= V(3);
w6(n)= V(4);
end

回答(1 个)

Walter Roberson
Walter Roberson 2019-5-24
You solve() on four equations involving 18 variables. If it found a solution at all, it is not likely to be for the four variables you happen to want.
solve() passing in quoted strings is no longer permitted as of R2018a. In versions before that it was permitted, but that form never substitutes in numeric values from the workspace. You have have defined numeric values for 14 of the variables and that (now obsolete) form of solve() would never know. You would have needed to use subs() to import numeric values in the workspace into quoted strings.
You should rewrite your code to not use quoted strings at that point. If you are using roughly R2015a or later, you can use == where the quoted string uses = . In earlier releases, you should convert the general form 'a=b' to (a)-(b)
  2 个评论
Taha Aminzadeh
Taha Aminzadeh 2019-5-24
编辑:Taha Aminzadeh 2019-5-24
At first, thank you very much for your answer. But I didn't get where should I replace = with ==. Please help me more.
By the way, as you can see in my code I tried using fsolve() and coplex numbers again in solve(), which do you reccomend me to use. Actually I had some problems with them, too.
Walter Roberson
Walter Roberson 2019-5-24
Pi = sym('pi');
Cosd = @(x) cos(x*Pi/180);
Sind = @(x) sin(x*Pi/180);
sx = solve(x_A-x_D+L1*Cosd(th1)+L2*Cosd(th2)+L3*Cosd(th3)==L4*Cosd(th4(n)), y_A-y_D+L1*Sind(th1)+L2*Sind(th2)+L3*Sind(th3)==L4*Sind(th4(n)), x_A-x_D+L1*Cosd(th1)+L5*Cosd(th2+al5)+L6*Cosd(th6)==L7*Cosd(th4(n)+al7), y_A-y_D+L1*Sind(th1)+L5*Sind(th2+al5)+L6*Sind(th6)==L7*Sind(th4(n)+al7));
I needed to define Sind and Cosd because sind and cosd do not exist for symbolic expressions

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by