When to use . matlab for equations
Ältere Kommentare anzeigen
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?
Akzeptierte Antwort
Weitere Antworten (1)
David Hill
am 19 Dez. 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.
Kategorien
Mehr zu Mathematics finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!