vector not produced missing some '.' ?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
something is wrong with this code
t=0:0.1:1;
g = (0.30/(2*(pi*t^3)^0.5))*exp((-0.30^2)/(4*t));
As the vector g never gets made, I'm sure I need to put some '.' somewhere but I really don't understand this whole '.' stuff
1 comentario
Paulo Silva
el 7 de Abr. de 2011
Sean answer is great for such cases, also when there's one dot missing matlab tells you what's the operation in the error message:
mtimes % before *
mdivide % before /
mpower % before ^
Respuesta aceptada
Paulo Silva
el 7 de Abr. de 2011
t=0:0.1:1;
g = (0.30./(2*(pi*t.^3).^0.5)).*exp((-0.30^2)./(4*t));
0 comentarios
Más respuestas (3)
Sean de Wolski
el 7 de Abr. de 2011
vectorize('g = (0.30/(2*(pi*t^3)^0.5))*exp((-0.30^2)/(4*t))');
A brainless way for us lazies.
4 comentarios
Matt Fig
el 7 de Abr. de 2011
As a general rule when dealing with operations on arrays, use a dot before every one of the three operators:
* / ^
If you do this you will be fine.
David Young
el 7 de Abr. de 2011
If you don't understand the operators, the most straighforward thing is to use
g = (0.30 ./ (2 .* (pi .* t .^ 3) .^ 0.5)) .* exp((-0.30 .^ 2) ./ (4 .* t));
so that all the operators behave as elementwise operators (which I guess is what you want). If you understand the difference, you can omit some of the dots, but they do no harm.
It's not all that hard really: *, / and ^ carry out matrix operations (like matrix multiplication, as defined here), while .*, ./ and .^ operate point by point on the elements of the matrices.
0 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!