When to use . matlab for equations
古いコメントを表示
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?
採用された回答
その他の回答 (1 件)
David Hill
2019 年 12 月 19 日
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.
カテゴリ
ヘルプ センター および File Exchange で Mathematics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!