Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Matrix dimensions must agree
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
James Tursa
am 25 Feb. 2020
Bearbeitet: James Tursa
am 25 Feb. 2020
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 Kommentare
John D'Errico
am 25 Feb. 2020
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 Kommentare
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!