Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Matrix dimensions must agree
1 回表示 (過去 30 日間)
古いコメントを表示
I am trying to plot a function in matlab and I am encountering the error: Matrix dimensions must agree.
my code is:
x=(1:14)
A=0.509998
mu1=0.387437
sigma1=0.0658118
mu2=0.384934
sigma2=0.0654886
la=5.82622e-10
y=A((1+(la/x.^12))*(1-exp(-(x-mu1)^2/(2*sigma1^2)))*(1-exp(-(x-mu2)^2/(2*sigma2^2))))
what is wrong with the function? Do I need . in other places?
Thanks for any help in advance.
Dylan
0 件のコメント
回答 (2 件)
James Tursa
2020 年 2 月 25 日
編集済み: James Tursa
2020 年 2 月 25 日
Yes, you need . in other places. Basically, to do element-wise operations you need to look for all of the x's in your equation and make sure the surrounding operations are element-wise. E.g., this
la/x.^2
should be
la./x.^2
And this
... )*( ...
should be
... ).*( ...
And this
(x-mu1)^2
should be
(x-mu1).^2
etc.
Also you have a typo. This
A(...
should be
A*(...
You might also double check to see if you want x.^12 or x.^2 in the equations.
0 件のコメント
John D'Errico
2020 年 2 月 25 日
You understood that you needed to use a dotted operator here: x.^12
There are also ./ and .* operators. For a VERY good reason. USE THEM.
Of course, expect some possible numerical problems, because some of what you are trying to do will result in numerical garbage.
Look carefully at what values x takes on. Then look carefully at what you are doing with it.
0 件のコメント
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!