Please help me understand the use of dot operator

570 views (last 30 days)
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 Comments
Tsansoterra
Tsansoterra on 18 Feb 2020
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.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 18 Feb 2020
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 Comments
Tsansoterra
Tsansoterra on 18 Feb 2020
Thank you. That was very insightful, and It gave me the asnwer I was looking for.
Star Strider
Star Strider on 18 Feb 2020
As always, my pleasure!
I do my best to provide complete explanations!

Sign in to comment.

More Answers (1)

David Hill
David Hill on 18 Feb 2020
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 Comment
Tsansoterra
Tsansoterra on 18 Feb 2020
Edited: Tsansoterra on 18 Feb 2020
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.

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!