Substitute multiple elements of multiple arrays with vectors

8 visualizaciones (últimos 30 días)
RODRIGO CRESPO MIGUEL
RODRIGO CRESPO MIGUEL el 1 de Feb. de 2023
Comentada: Dyuman Joshi el 3 de Abr. de 2023
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

Respuestas (1)

Varun
Varun el 24 de Mzo. de 2023
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
sM = 
S = subs(sM,{X,Y},{[0 sqrt(sym(2)); sqrt(sym(2)) 0], [1 -1; -2 1]})
S = 
Ssym = symmatrix2sym(S)
Ssym = 
You may refer to this documentation for more information:
  2 comentarios
RODRIGO CRESPO MIGUEL
RODRIGO CRESPO MIGUEL el 3 de Abr. de 2023
The problem is that I want to substitute entire time dependant vectors in each element of the matrix.
For example, let A be a 2x2 matrix. I want each of those four elements substituted by a different (let's say 1:100) vector. Can I do that with subs?
Dyuman Joshi
Dyuman Joshi el 3 de Abr. de 2023
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]
A = 
subs(A,{x,y,z,q},{1:10,1:10,1:10,1:10})
ans = 

Iniciar sesión para comentar.

Productos


Versión

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by