I am trying to compute dynamics of 3 DOF robot using Robotics Toolbox by executing this code:
robot.accel(q, zeros(1,3), zeros(1,3))
But I am getting this error: Assignment has more non-singleton rhs dimensions than non-singleton subscripts
My robot is:
L(1)= Link([0 0.03 0 -pi/2]);
L(2)= Link([0 0 0.28 0]);
L(3)= Link([0 0 0.2 0]);
L(1).m = 1;
L(2).m = 4;
L(3).m = 3;
L(1).r=[0 0 -0.015];
L(2).r=[0.14 0 0];
L(3).r=[0.1 0 0];
ax1=0.03; ay1=0.03; az1=0.03;
ax2=0.28; ay2=0.05; az2=0.05;
ax3=0.2; ay3=0.05; az3=0.05;
I1=1/12*[ay1^2+az1^2 0 0; 0 ax1^2+az1^2 0; 0 0 ax1^2+ay1^2];
I2=4/12*[ay2^2+az2^2 0 0; 0 ax2^2+az2^2 0; 0 0 ax2^2+ay2^2];
I3=3/12*[ay3^2+az3^2 0 0; 0 ax3^2+az3^2 0; 0 0 ax3^2+ay3^2];
L(1).I=I1;
L(2).I=I2;
L(3).I=I3;
q=[0 0 0]
robot=SerialLink(L);
The error was due to no mention of motor inertias. I have set them to:
for i=1:3
robot.links(i).Jm = 2.1184*10^-4;
end
and the error is gone while using robot.accel command.
Related
I'm calculating the eigenvalues of a 8x8-matrix including a symbolic variable "W". Plotting the 8 eigenvalues as functions of W returns a strange result in the plot which looks like someone rode his bike over my diagram.
For the 2nd matrix, where I just set some off-diagonal elements equal to 0, everything works fine. But I don't know what the problem with the 1st one is.
syms W;
w0=1/780;
wl=1/1064;
h=1; % for now this seems unnecessary, but I want to change this value later on
% This is the 1st matrix which causes some strange plotting results
A=h*[w0+3*wl 2*W 0 0 0 sqrt(3)*W 0 0;
2*W 4*wl 0 0 0 0 0 0;
0 0 2*wl+w0 sqrt(3)*W 0 0 0 sqrt(2)*W;
0 0 sqrt(3)*W 3*wl 0 0 0 0;
0 0 0 0 wl+w0 sqrt(2)*W 0 0;
sqrt(3)*W 0 0 0 sqrt(2)*W 2*wl 0 0;
0 0 0 0 0 0 w0 W;
0 0 sqrt(2)*W 0 0 0 W wl];
% This is the 2nd matrix for which everything is working fine
B=h*[w0+3*wl 2*W 0 0 0 0 0 0;
2*W 4*wl 0 0 0 0 0 0;
0 0 2*wl+w0 sqrt(3)*W 0 0 0 0;
0 0 sqrt(3)*W 3*wl 0 0 0 0;
0 0 0 0 wl+w0 sqrt(2)*W 0 0;
0 0 0 0 sqrt(2)*W 2*wl 0 0;
0 0 0 0 0 0 w0 W;
0 0 0 0 0 0 W wl];
X = eig(A);
X2 = eig(B);
eva22 = X2(1);
eva1 = X(1);
figure(1);
fplot(X2,[-0.002 0.002]);
hold on;
fplot(X,[-0.002 0.002]);
hold off;
xlabel('Rabi frequency [THz]','FontSize',11);
ylabel('dressed states','FontSize',11);
grid on;
box on;
I'm expecting the plot for matrix A to just be similar to the plot of matrix B, but somehow it doesn't work properly. I'd appreciate some tips and tricks how to fix this.
The second plot looks like that because the eigenvalues of B are imaginary. When using plot(), it plots the real part of complex numbers by default, but apparently fplot() doesn't. You can do fplot(real(X), [-0.002 0.002]) instead to plot just the real part of the eigenvalues (assuming that's what you want).
I'm new in image processing with matlab, when i wrote this code :
A = [0 0 1 0 0; 0 1 1 1 0; 1 1 1 1 1; 0 1 1 1 0; 0 0 1 0 0];
B = [A A A A A; A A A A A; A A A A A; A A A A A; A A A A A];
imshow(A, 2)
imshow(B, 2)
I got this error :
Error using imshow>preParseInputs (line 439)
Invalid IMSHOW syntax.
Error in imshow (line 214)
varargin_translated = preParseInputs(varargin{:});
The function imshow() is not deprecated at all and it does take a double matrix as a first input. However, the second input (the colormap) cannot be a scalar, it must be a matrix with 3 columns where each row specifies an RGB color value. By doing
A = [0 0 1 0 0; 0 1 1 1 0; 1 1 1 1 1; 0 1 1 1 0; 0 0 1 0 0];
imshow(A,[1 1 1])
a small all-white picture appears. It is up to you, now, to adjust the colormap that better suits your goals.
I was searching for the implementation of Perona & Malik filter in Matlab, when i found this link "the link has an implementation for Perona and Malik filter using Matlab"
but there is the matrices that i didn't understand what is the use of them:
% 2D convolution masks - finite differences.
hN = [0 1 0; 0 -1 0; 0 0 0];
hS = [0 0 0; 0 -1 0; 0 1 0];
hE = [0 0 0; 0 -1 1; 0 0 0];
hW = [0 0 0; 1 -1 0; 0 0 0];
hNE = [0 0 1; 0 -1 0; 0 0 0];
hSE = [0 0 0; 0 -1 0; 0 0 1];
hSW = [0 0 0; 0 -1 0; 1 0 0];
hNW = [1 0 0; 0 -1 0; 0 0 0];
any one has an idea what are these matrices, or what do they mean?
These are the kernels for getting the gradients in North, East, South and West directions, and also for dialgonals (NE = North East etc.).
hN = [0 1 0; 0 -1 0; 0 0 0];
or nicely formatted:
0 1 0
0 -1 0
0 0 0
Convolution of this kernel with an image yields the gradient in "North direction". Basically, this is a mask of factors that you apply to all your 3x3 areas of your image and since all except two entries are 0, what you get is the pixel at the top minus that in the center, thus the gradient in y-direction.
I have a function Matrices that gives me Along. I want Along from first function to pass another function MatricesElse as an argument. This code has error, why?
function theOutput = Matrices()
theOutput = Along;
function MatricesElse(Along)
disp(theInput); % // Will print value of Along returned from first function,
syms teta q u w Se Sth v p r o Y SR SA s
% // Aircraft Equations of Longitudinal Motion
Ilong=[1 0 0 0;0 1 0 0; 0 1 0 0;0 0 0 1];
Xlong=[teta;q;u;w];
Ulong=[Se;Sth];
Xlong=(inv(s*Ilong-Along))*Blong*Ulong;
teta=Xlong(1,1)
q=Xlong(2,1)
u=Xlong(2,1)
w=Xlong(3,1)
% // Aircraft Equations of Lateral Motion
Ilat=[1 0 0 0 0;0 1 0 0 0;0 0 1 0 0;0 0 0 1 0;0 0 0 0 1];
Xlat=[v;p;r;o;Y];
Ulat=[SR;SA];
Xlat=(inv(s*I-Alat))*Blat*Ulong;
v=Xlat(1,1)
p=Xlat(2,1)
r=Xlat(3,1)
o=Xlat(4,1)
Y=Xlat(5,1)
end
Short explanation: you are trying to call a private variable of function Matrices() outside of this function, that's why it doesn't work.
This code should work. Note that the name CalcMatrix can differ from theOutput and Along, but all of these variables have the same content:
function main
CalcMatrix = Matrices()
MatricesElse(CalcMatrix)
function theOutput = Matrices()
theOutput = Along;
function MatricesElse(Along)
disp(theInput); % // Will print value of Along returned from first function,
syms teta q u w Se Sth v p r o Y SR SA s
% // Aircraft Equations of Longitudinal Motion
Ilong=[1 0 0 0;0 1 0 0; 0 1 0 0;0 0 0 1];
Xlong=[teta;q;u;w];
Ulong=[Se;Sth];
Xlong=(inv(s*Ilong-Along))*Blong*Ulong;
teta=Xlong(1,1)
q=Xlong(2,1)
u=Xlong(2,1)
w=Xlong(3,1)
% // Aircraft Equations of Lateral Motion
Ilat=[1 0 0 0 0;0 1 0 0 0;0 0 1 0 0;0 0 0 1 0;0 0 0 0 1];
Xlat=[v;p;r;o;Y];
Ulat=[SR;SA];
Xlat=(inv(s*I-Alat))*Blat*Ulong;
v=Xlat(1,1)
p=Xlat(2,1)
r=Xlat(3,1)
o=Xlat(4,1)
Y=Xlat(5,1)
I am trying to use RSM and calculate 3rd order polynomials.for quadratic below is given in Matlab Help:
stats = regstats(rsmOutput,rsmMatrix,'quadratic','beta');
b = stats.beta; % Model coefficients
How can I calculate 3rd order coefficients? My reason is that with quadratic I have rsquare of 93% and my observed responses is third order.
For
stats = regstats(y,X,model,whichstats)
the 'model' can be a matrix of model terms accepted by the 'x2fx' function. See x2fx for a description of this matrix and for a description of the order in which terms appear. You can use this matrix to specify other models including ones without a constant term.
modelMatrix = [0 0 0;
1 0 0;
0 1 0;
0 0 1;
1 1 0;
1 0 1;
0 1 1;
2 0 0;
0 2 0;
0 0 2;
1 1 1;
2 1 0;
2 0 1;
1 2 0;
1 0 2;
0 2 1;
3 0 0;
0 3 0;
0 0 3];
stats = regstats(rsmOutput,rsmMatrix,modelMatrix,'beta');