Is there a one line implementation for this?
이전 댓글 표시
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
답변 (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
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
2022년 11월 23일
Ah you are right, I mised the exp()
카테고리
도움말 센터 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!