How can I make a variable matrix?
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Steven Lord
on 23 May 2023
You could do this:
syms U [7 1]
U
But be careful what you name your variable. Note that not only is U created but so are U1, U2, ...
whos
3 Comments
Walter Roberson
on 23 May 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.
More Answers (1)
Walter Roberson
on 23 May 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
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!