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!