How can i assign sybolic values to ymbolic variables in an symbolic matrix?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi folks,
I actually want to write a function for any kind of rotational robot. The function should give back the Translation Matrixes and the Jacobi Matrix. To do that I need to differentiate my final T Matrix.
So my code shoudl do this:
Pseudo Code:
n = 10
c_array = create_symbolic_array('c',[1 n]) %% c1 c2 ... cn
t_array = create_symbolic_array('th', [1 n]) %% th1 th2 ... thn
%% Loop to assign c1 = cos(th1)
loop(1:1:n)
c_array(1,n) = cos(th(1,n))
%result should be
c1 = cos(th1)
c2 = cos(th2)
.
.
.
cn = cos(thn)
cn should be an symbolic type with the value assigned cos(th1), if it isnt an array its fine, but i need c1 c2 c3 and so with the cos(thn) assigned,
I tried a lot of things.
Here one of my examples coded in MATLAB
% test data
a = [100 100 100 100]
alpha = [90 90 90 90]
d = [0 10 10 10]
theta1=[0 0 0 0]
sz_a = size(a,2);
sz_alpha = size(alpha,2);
sz_d = size(d,2);
sz_th = size(theta1,2)
theta = sym('th', [1,sz_th])
cosinusse = sym('c', [1,sz_th])
sinussse = sym("s", [1,sz_th])
T0_n = zeros(sz_th)
Ti_j= zeros(sz_th)
%symbolic array
syms('c',[1 4])
%% Of course this needs to be looped, but sprintf do not assign it is only printing
sprintf("%s=%d", strcat('c', num2str(1)), cos(theta1(1,1)))
% also I tried
for i = 1:sz_th
c(1,i) = cos(theta(1,i))
end
for i = 1:sz_th
sprintf("%s=%d", strcat('c', num2str(i)), cos(theta1(1,i)))
end
I hope you guys can help me, i would be really happy.
0 comentarios
Respuestas (1)
Steven Lord
el 2 de Dic. de 2021
Can you create variables named c1, c2, c3, etc.? Yes.
Should you do this? The general consensus is no. See that Answers post for an explanation and alternatives.
In this particular case, wherever you would have used c1 instead use c(1).
c = sym('abc', [1, 5])
y = c(1)+c(3)
subs(y, c, (1:5).^2)
Ver también
Categorías
Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!