When to use . matlab for equations
Mostrar comentarios más antiguos
When do I use . in matlab
For example:
theta = 0:1:90;
g = 9.81;
u = ((-6*g)./(((cos(theta)).^2)-sin(2.*theta))).^1/2;
plot(theta, u)
gives me a a graph with negative values but when I enter for theta for the same equation I get positive values...
Where do I place the '.''s within u?
Respuesta aceptada
Más respuestas (1)
David Hill
el 19 de Dic. de 2019
The '.' is for element wise computations. Multipling a scalar by a vector or matrix does not require it.
u = ((-6*g)./(((cos(theta)).^2)-sin(2*theta))).^1/2;% 1./(matrix or vector) needs it (you are taking the recipical of each element) and (vector or matrix) .^ power needs it (you are raising each element to the power), but sin(2*theta) does not.
Any time you are multiplying, dividing, raising a vector or matrix by another matrix or vector of the same size and you want to perform the operation element by element you need the dot.
Categorías
Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!