How to calculate Matrix A?! (Fitting or ...)
3 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I need to calculate Matrix A, as you can see in the photo I have attached. (my system is a lot bigger, I simplified it in several rows and columns so it can be understood easily)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/157587/image.jpeg)
I know it can be done by Fitting, however, I do not know how I can define matrix A for this purpose. In Fitting, we can define xdata=F2 and ydata=F1; but what about A?!
If also, you know any other method to calculate A, please let me know.
Thanks, Peyman
2 个评论
回答(1 个)
John D'Errico
2014-2-25
You have a bi-diagonal matrix. One common trick is to use diag to create the main diagonal and then the sub-diagonal matrix, adding the two matrices together. Thus if a_main is a vector of main diagonal entries, and a_sub, the vector of the sub-diagonal entries...
a_main = rand(1,7);
a_sub = rand(1,6);
A = diag(a_main) + diag(a_sub,-1)A =
0.75774 0 0 0 0 0 0
0.27692 0.74313 0 0 0 0 0
0 0.046171 0.39223 0 0 0 0
0 0 0.097132 0.65548 0 0 0
0 0 0 0.82346 0.17119 0 0
0 0 0 0 0.69483 0.70605 0
0 0 0 0 0 0.3171 0.031833
Better is to learn to use sparse matrices, here the appropriate function is spdiags, which will create the complete matrix in one call. The nice thing about a sparse matrix is the storage savings as well as a speed boost for large problems.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!