# How can I make a variable matrix?

7 visualizaciones (últimos 30 días)
mahdi el 23 de Mayo de 2023
Comentada: Walter Roberson el 23 de Mayo de 2023
I want to make variable matrices for my matrix equation: (2*A_11*r_i^2*C(1,2)*[U_1; ...; U_N])+(2*A_11*r_i*C(1,1)*[U_1; ...; U_N])-(2*A_11*[U_1; ...; U_N])+(A_11*r_i^2*W0*C(1,2)*[W_1; ...; W_N])+(((A_11*r_i)-(Nu*A_11*r_i))*W0*C(1,1)*[W_1; ...; W_N])=0 which are [U_1; ...; U_N] and [W_1; ...; W_N]. If anyone could help I would be thankful. A_11 is a scalar and r_i is a vector [0 0.0334 0.125 0.250 0.375 0.4665 0.500] and C(1,2) and C(1,1) are 7*7 matrices and W0 's are scalar. Actually this is a equation system which has 2 more equations and I need to solve it and use the results for W0 's and make a loop with some error function and also some boundary conditions. But for now i just wanna figure the part of variable matrix out first. Code I used is here and it is not right:
syms U
for N = 1:7
U(7,1) = U(N);
end
disp(U)
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Steven Lord el 23 de Mayo de 2023
You could do this:
syms U [7 1]
U
U =
But be careful what you name your variable. Note that not only is U created but so are U1, U2, ...
whos
Name Size Bytes Class Attributes U 7x1 8 sym U1 1x1 8 sym U2 1x1 8 sym U3 1x1 8 sym U4 1x1 8 sym U5 1x1 8 sym U6 1x1 8 sym U7 1x1 8 sym cmdout 1x33 66 char
##### 3 comentariosMostrar 1 comentario más antiguoOcultar 1 comentario más antiguo
mahdi el 23 de Mayo de 2023
nvm my last comment, your answer is good enough I think, thank you.
Walter Roberson el 23 de Mayo de 2023
As I already showed, that code will end up with a vector of U_1 to U_6 and then an extra U_6 .
Each assignment to U(7,1) does not change any of the other locations in U. The first iteration replaces U(7,1) with U1. The second iteration replaces U(7,1) with U2. And so on to the 6th iteration replacing U(7,1) with U6. Then the 7th iteration is doing U(7,1) = U(7) but U(7) is currently U6 because of the previous iteration, so U(7,1) stays U6.

Iniciar sesión para comentar.

### Más respuestas (1)

Walter Roberson el 23 de Mayo de 2023
syms U [7 1]
for N = 1:7
U(7,1) = U(N);
end
disp(U)
I suspect this is not what you want. I suspect what you want is just
syms U [7 1]
U
U =
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Number Theory en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by