Error message - matrix dimensions must agree
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi I am inputting the following line of code to solve a laplace irreducible quadratic equation. Its quite long and I have checked the brackets numerous times and I think they are correct. I think the problem is arising due to the use of the multiplication sign and I am unsure where I need to use the .* and the *. Could someone please advise? Thank you.
i=(c/b)*((1-(exp((-a/2)*t))).*cos(sqrt(b-((a^2)/4))*t)+(a/2)*(1/(sqrt(b-(a^2)/4).*t))*sin(sqrt(b-(a^2)/4)*t));
I then get the following error message
Error using / Matrix dimensions must agree.
Error in laplace (line 104) i=(A)*((1-(exp((-a/2)*t))).*cos(sqrt(b-((a^2)/4))*t)+(a/2)*(1/(sqrt(b-(a^2)/4).*t))*sin(sqrt(b-(a^2)/4)*t));
댓글 수: 0
답변 (2개)
Chris C
2014년 3월 13일
The .* is used whenever you have to arrays or matrices that you want to multiply each individual element with the corresponding element in the other array or matrix. * is used when you want good old fashioned matrix muliplication. For me to be more clear I need to know what the variables in your code stand for (i.e. arrays, constants, matrices).
Chris C
2014년 3월 13일
Okay, I found them (I think). In line 104 that you reference above it looks like there are several variables referenced: A,a,t and b. A, a and b are all contants and t is your only array. Therefore every instance of t multiplied or divided by itself needs a . before the operation.
I found one instance that hasn't been done correctly i.e...
(1/(sqrt(b-(a^2)/4).*t))*(sin(sqrt(b-(a^2)/4).*t))))
There needs to be a . between these two terms and it should look like this...
(1/(sqrt(b-(a^2)/4).*t)).*(sin(sqrt(b-(a^2)/4).*t))))
Hope that helps.
댓글 수: 2
Chris C
2014년 3월 13일
No problem. Please don't forget to "Accept" an answer that satisfactorily answers your question. :)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!