Substitute multiple elements of multiple arrays with vectors
5 次查看(过去 30 天)
显示 更早的评论
Hello. From solving the following matrix equation (with matrices of arbitrary size NxN) I obtain the solution to my problem functions cepsepssym:
syms cepsepssym [nvars nvars]
syms cBeps [nvars nvars]
syms cepsB [nvars nvars]
syms Bautocorr
equations = -cepsepssym*transpose(matrizGamma)-matrizGamma*cepsepssym+cepsB+cBeps+diag(vecsigmas)*Bautocorr==0;
sol=solve(equations,cepsepssym);
solvec=reshape(transpose(sol),1,[]);
But now I want to substitute each of the other variables (i.e., each element of the matrixes cBeps and cepsB, and Bautocorr) by a vector (given by known time dependent functions). Is there an easy way to do that?
Thank you very much in advance
0 个评论
回答(1 个)
Varun
2023-3-24
Hello!
You can use the “subs” function in MATLAB to substitute each of the variables by a vector. For example, for a simple matrix product equation, we have
syms X Y [2 2] matrix
sM = X*Y
S = subs(sM,{X,Y},{[0 sqrt(sym(2)); sqrt(sym(2)) 0], [1 -1; -2 1]})
Ssym = symmatrix2sym(S)
You may refer to this documentation for more information:
2 个评论
Dyuman Joshi
2023-4-3
You can do that, but note that you won't obtain every unique combination in output, just one-to-one combination.
syms x y z q
A = [sin(x) cos(y); exp(z) q]
subs(A,{x,y,z,q},{1:10,1:10,1:10,1:10})
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Number Theory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!