Please help me understand the use of dot operator

575 次查看(过去 30 天)
Hello. I have been having this same problem in a lot of the homework assignments I have been given so far.
What I am trying to do is use the while loop to create values for J, and in the same loop I am trying to use those values of
J to create a new array with the values from tau.
clc; clear ; clear all
F = 10; %Newtons
T = F*0.1 ; %Work
r = 0:5; %mm
i = 1
while i < 6
J = (.5*pi)*r.^4
tau(i) = (T*r)/J
i = i + 1;
end
  2 个评论
Tsansoterra
Tsansoterra 2020-2-18
How do I get the values of tau using the values of J and r ? The method for J where I used a dot operator does not work for tau to cycle through the values of the array.

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2020-2-18
The dot operator, used with multiplication, division, and exponentiation, creates element-wise oiperations. See Array vs. Matrix Operations for a full explanation.
The one exception to that is the use of the dot operator in creating matrix transposes. The ‘regular’ matrix transpose (') creates the complex-conjugate transpose of a complex vector or matrix. Using the (.') creates the transpose without doing the complex-conjugate operation.
  3 个评论
Tsansoterra
Tsansoterra 2020-2-18
Thank you. That was very insightful, and It gave me the asnwer I was looking for.
Star Strider
Star Strider 2020-2-18
As always, my pleasure!
I do my best to provide complete explanations!

请先登录,再进行评论。

更多回答(1 个)

David Hill
David Hill 2020-2-18
Not sure what you want tau to be. Currently you have an array (T*r) divided by another array (J). If you want to generate a tau matrix, then:
tau(i,:)=(T*r)./J;
If tau is suppose to be a 6 element array, then I suppect what you meant was:
F = 10; %Newtons
T = F*0.1 ; %Work
r = 0:5; %mm
J = (.5*pi)*r.^4;
tau = (T*r)./J;%need ./for element-wise operations
  1 个评论
Tsansoterra
Tsansoterra 2020-2-18
编辑:Tsansoterra 2020-2-18
Hi David. Thank you for your response. I apologize for my laymen terms as this language is very new to me.
I have 3 equations ; T=F(0.1) , J=(pi/2)*r^4 , and tau = (T*r)/J
given ; r = 0:5 , T = 100, tau(max) = 100
I ultimately need to graph tau by r.
Using a while loop I am trying to get an array of answers for tau, so that I can graph it. Tau depends on the value J.
So what I want to do is run a while loop 5 times to represent each value of r. In this loop I am trying to solve for J, and then solve for tau using the found values of J.
Thanks again for your time.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by