Matrix dimensions must agree.
3 ビュー (過去 30 日間)
古いコメントを表示
t = [0:0.1:10]
L1 = linspace(4,5,101)
L2 = linspace(6,7,101)
ft1 = 1 - 2*t.^2
ft2 = 3*t - 2*t.^3
t1 = (L1.*y-diff(diff(ft1)))/(2*diff(ft1))
t2 = (L2.*y-diff(diff(ft2)))/(2*diff(ft2))
I dont understand what Im doing wrong here. t, L1, L2, ft1 and ft2 are all 1x101 doubles but i keep getting back matrix dimentions must agree. Im sure the problem has something to do with the fact that im using vectors and the MatLab wants matracies, but im not sure. If anyone knows what im donig wrong to get please let me know. Thank you!
0 件のコメント
回答 (1 件)
Cris LaPierre
2021 年 1 月 24 日
You haven't told us what y is.
Also be aware that diff returns a vector with one less element than it started with. You perform a diff twice on the numerator, so the resulting length is 99, and once on the denominator, so its resulting length is 100. Only L1 and L2 have lengths of 101 in your calculations.
1 件のコメント
Walter Roberson
2021 年 1 月 24 日
The problem is worse than that. Even if the two lengths were the same,
rand(1,5)/rand(1,5)
... A scalar?? Probably not what was expected.
Remember that / is mrdivide, and that generally A/B is similar to A*pinv(B) and even when it is not quite like that, A/B acts like a least squared fitting operation .
It is much more likely that the ./ rdivide element-by-element division was intended.
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!