Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Matrix dimensions must agree

2 vues (au cours des 30 derniers jours)
Dylan Girodat
Dylan Girodat le 25 Fév 2020
Clôturé : MATLAB Answer Bot le 20 Août 2021
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

Réponses (2)

James Tursa
James Tursa le 25 Fév 2020
Modifié(e) : James Tursa le 25 Fév 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.

John D'Errico
John D'Errico le 25 Fév 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.

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by