Is there a one line implementation for this?
Mostrar comentarios más antiguos
t = sym('t',[1,10]);
A = {};
A {1,1} = sin(t);
A {1,2} = cos(t);
A {2,1} = tan(t);
A {2,2} = t;
result = {};
% For the below lines, it would be nice to have a one line implementation!
for i = 1:2
for j = 1:2
result{i,j} = eval(subs(exp(A{i,j}),t,{1:10}));
end
end
Respuestas (2)
t = sym('t',[1,10]);
A = {};
A {1,1} = sin(t);
A {1,2} = cos(t);
A {2,1} = tan(t);
A {2,2} = t;
result = {};
% For the below lines, it would be nice to have a one line implementation!
for i = 1:2
for j = 1:2
result{i,j} = eval(subs(exp(A{i,j}),t,{1:10}));
end
end
result
one_line_result = reshape(mat2cell(double(subs(exp([A{:}]),t,{1:10})),1,10*ones(1,4)),2,[])
syms t; M = [sin(t), cos(t); tan(t), t]; result = arrayfun(@(I,J) double(subs(M(I,J), t, 1:10)), [1 1; 2 2], [1 2; 1 2], 'uniform', 0)
Note: you should never eval() a symbolic expression or symbolic function. eval() has no documented meaning for symbolic expressions or symbolic functions, and the undocumented behaviour will give you errors or unexpected results.
2 comentarios
syms t;
M = [sin(t), cos(t); tan(t), t];
result = arrayfun(@(I,J) double(subs(exp(M(I,J)), t, 1:10)), [1 1; 2 2], [1 2; 1 2], 'uniform', 0)
Walter Roberson
el 23 de Nov. de 2022
Ah you are right, I mised the exp()
Categorías
Más información sobre Symbolic Math Toolbox en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!