How can I make a variable matrix?

조회 수: 7 (최근 30일)
mahdi
mahdi 2023년 5월 23일
댓글: Walter Roberson 2023년 5월 23일
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)

채택된 답변

Steven Lord
Steven Lord 2023년 5월 23일
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
mahdi
mahdi 2023년 5월 23일
nvm my last comment, your answer is good enough I think, thank you.
Walter Roberson
Walter Roberson 2023년 5월 23일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2023년 5월 23일
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 = 

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by