MATLAB Answers

0

I have 2 questions: I am having invalid syntax at '='. possible a']' missing. Please help check what could be the problem. Secondly please advise me if the code for constant time for torque at position 4 is correct

Asked by Justus Opara on 23 Sep 2019
Latest activity Commented on by dpb
on 23 Sep 2019
  1. dphi(1,:)=[-1 0 -L2/2.*sin(y(i,3)) zeros(1,6)];
2. conTA.time=time4;
conTA.signals.values=T4';
conTA.signals.dimensions= 1;
This is the script done so far, I am confused if I am on the right track:
g=9.81;
d2r=pi/180;
rho=2750;
w=0.04;
th=0.02;
L2=0.15;
L3=1.25;
L4=0.15;
LBC=0.5;
T4=0.0015;
time4=0.45;
H=0.45; % H=OA, assumed height to implement simulation
d=0.15; % d=OD, assumed distance to implement simulation
m2=rho.*w.*th.*L2;
I2=m2.*L2.^2/12;
m3=rho.*w.*th.*L3;
I3=m3.*L3.^2/12;
m4=rho.*w.*th.*L4;
I4=m4.*L4.^2/12;
M=zeros(9,9);
M(1,1)= m2; M(2,2)= m2; M(3,3)= I2;
M(4,4)= m3; M(5,5)= m3; M(6,6)= I3;
M(7,7)= m4; M(8,8)= m4; M(9,9)= I4;
Minv=inv(M);
tf=0.75; tspan=[0 tf];
load torque %loads T4,time4
%Define the conTA structure representing the torque data for Simscape
conTA.time=time4;
conTA.signals.values=T4';
conTA.signals.dimensions= 1;
%the initial guess for the initial configuration and the initial position:
phi20=20.*d2r;
q0=[L2/2.*cos(phi20); L2/2.*sin(phi20); phi20; d+L2.*cos(phi20); H+L2.*sin(phi20); 300.*pi/180; ...
L4/2.*cos(phi20); L4/2.*sin(phi20); pi/6]
qq=pos_advancer(q0,L2,L3,L4,LBC,H,d,phi20);
%the initial conditions and invoking the solver
y0=[qq;zeros(9,1)];
options=odeset('RelTol', 1e-6, 'AbsTol',1e-9);
[t,y]=ode45(@difffilm_advancer,tspan,y0,options,M,Minv,L2,L3,L4,LBC,m2,m3,m4,g,T4,time4);
%Recovering the Lagrange multipliers and the accelerations over the simulation time interval
T4=spline(time4,T4,t);
N=length(t); Lam=zeros(8,N); XX=zeros(9,N);
xD=zeros(1,N);yD=zeros(1,N);
for i=1:N
%position for film advancer in initial position
phi=[d-q(1)+ L2/2.*cos(y(i,3));...
H-q(2)+L2/2.*sin(y(i,3));...
q(1)+L2/2.*cos(y(i,3))-q(3)-(L3/2-LBC).*cos(y(i,6));...
q(2)+L2/2.*sin(y(i,3))-q(4)-(L3/2-LBC).*sin(y(i,6));...
q(3)+L3/2.*cos(y(i,6))-q(5)-L4/2.*cos(y(i,9));...
q(4)+L3/2.*sin(y(i,6))-q(6)-L4/2.*sin9y(i,9);...
q(5)-L4/2.*cos(y(i,9));...
q(6)-L4/2.*sin(y(i,9));...
% jacobian for film_advancer in initial position
dphi(1,:)=[-1 0 -L2/2.*sin(y(i,3)) zeros(1,6)];
dphi(2,:)=[0 -1 L2/2.*cos(y(i,3)) zeros(1,6)];
dphi(3,:)=[1 0 -L2/2.*sin(y(i,3)) -1 0 (L3/2-LBC).*sin(y(i,6)) zeros(1,3)];
dphi(4,:)=[0 1 L2/2.*cos(y(i,3)) 0 -1 -(L3/2-LBC).*cos(y(i,6)) zeros(1,3)];
dphi(5,:)=[zeros(1,3) 1 0 -L3/2.*sin(y(i,6)) -1 0 L4/2.*sin(y(i,9))];
dphi(6,:)=[zeros(1,4) 1 L3/2.*cos(y(i,6)) 0 -1 -L4/2.*cos(y(i,9))];
dphi(7,:)=[zeros(1,6) 1 0 L4/2.*sin(y(i,9))];
dphi(8,:)=[zeros(1,7) 1 -L4/2.*cos(y(i,9))];
% Gamma vector:
gam(1)=L2/2.*cos(y(i,3)).*y(i,12).^2;
gam(2)=L2/2.*sin(y(i,3)).*y(i,12).^2;
gam(3)=L2/2.*cos(y(i,3)).*y(i,12).^2-(LBC-L3/2).*cos(y(i,6)).*y(i,15).^2;
gam(4)=L2/2.*sin(y(3)).*y(i,12).^2-(LBC-L3/2).*sin(y(i,6)).*y(i,15).^2;
gam(5)=L3/2.*cos(y(i,6)).*y(i,15).^2-L4/2.*cos(y(i,9)).*y(i,18).^2;
gam(6)=L3/2.*sin(y(i,6)).*y(i,15).^2-L4/2.*sin(y(i,9)).*y(i,18).^2;
gam(7)=-L4/2.*cos(y(i,9)).*y(i,18).^2;
gam(8)=-L4/2.*sin(y(i,9)).*y(i,18).^2;
% Force vector:
f=[0; -m2.*g;0;0; -m3.*g; 0;0; -m4.*g; T4(i)];
%====================================
A1=dphi.*Minv.*dphi'; b1=gam'-dphi.*Minv*f;
lam=A1\b1;
X=M\(f'+dphi'*lam);
Lam(:,i)=lam; % lagrange multipliers
XX(:,i)=X; % accelerations
xE(i)=y(i,4)-L3.*cos(y(i,6))/2; % for trajectory of E
yE(i)=y(i,5)-L3.*sin(y(i,6))/2; % for trajectory of E
end

  3 Comments

With braces, it's probable the actual missing one is in line preceding or following the actual error line...that's just where the parser actually got to but the unclosed opening [ is likely before there...
We have no way at all to know whether something is correct in isolation...
As was surmised above, your missing closing brace looks to be in...
phi=[d-q(1)+ L2/2.*cos(y(i,3));...
H-q(2)+L2/2.*sin(y(i,3));...
q(1)+L2/2.*cos(y(i,3))-q(3)-(L3/2-LBC).*cos(y(i,6));...
q(2)+L2/2.*sin(y(i,3))-q(4)-(L3/2-LBC).*sin(y(i,6));...
q(3)+L3/2.*cos(y(i,6))-q(5)-L4/2.*cos(y(i,9));...
q(4)+L3/2.*sin(y(i,6))-q(6)-L4/2.*sin9y(i,9);...
q(5)-L4/2.*cos(y(i,9));...
q(6)-L4/2.*sin(y(i,9));...

Sign in to comment.

0 Answers