build m x m matrix
古いコメントを表示
Hello, I wanna build a matrix of m nods. I have some questions:
1-
if F=[-3 2 -3]
for I=1:m;end
B=eye(I)*F; ---------(1)
the problem here is F in eq (1) is not allowed in matlab, what I have to do to built that matrix which affected by different values of m?
2-
A=[5 -3];C=[-3 4];
I wanna use use the three matrices (A,B,C), to get the result to be like
D= [ 5 -3 0 0 0;
-3 2 -3 0 0;
0 -3 2 -3 0;
0 0 -3 2 -3;
0 0 0 -3 4 ]
What do u suggest??
thanks
採用された回答
その他の回答 (2 件)
Image Analyst
2014 年 9 月 28 日
0 投票
First of all, in #1, the for loop does nothing. There is an end on the same line and nothing in between so the for loop just iterates but does no commands because no commands are inside it.
Secondly, in your formula 1, I think you want to use .* (element by element multiplication) instead of * (matrix multiplication), and it would only work if F has "I" rows. Since eye(I) is square, F must be have the same number of rows as eye(I) has columns.
For #2, I'm not seeing how matrix D was constructed from A, B, and C. Please explain.
Andrei Bobrov
2014 年 9 月 28 日
F = [-3 2 -3];
A=[5 -3];
C=[-3 4];
out = full(spdiags(ones(5,1)*F,-1:1,5,5));
out(1:2) = A;
out(end-1:end) = C;
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!