Matrix dimensions must agree.
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Cris LaPierre
le 24 Jan 2021
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 commentaire
Walter Roberson
le 24 Jan 2021
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.
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!