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!

답변 (1개)

Cris LaPierre
Cris LaPierre 2021년 1월 24일

2 개 추천

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

The problem is worse than that. Even if the two lengths were the same,
rand(1,5)/rand(1,5)
ans = 0.7528
... 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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

릴리스

R2020b

질문:

2021년 1월 24일

댓글:

2021년 1월 24일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by