Is there a one line implementation for this?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (2)
Voss
am 23 Nov. 2022
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,[])
0 Kommentare
Walter Roberson
am 23 Nov. 2022
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 Kommentare
Siehe auch
Kategorien
Mehr zu Formula Manipulation and Simplification finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!