Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Matrix dimensions must agree

2 visualizaciones (últimos 30 días)
Dylan Girodat
Dylan Girodat el 25 de Feb. de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 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

Respuestas (2)

James Tursa
James Tursa el 25 de Feb. de 2020
Editada: James Tursa el 25 de Feb. de 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 el 25 de Feb. de 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.

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by