Please help me understand the use of dot operator

583 visualizaciones (últimos 30 días)
Tsansoterra
Tsansoterra el 18 de Feb. de 2020
Comentada: Star Strider el 18 de Feb. de 2020
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 comentarios
KSSV
KSSV el 18 de Feb. de 2020
Okay..what is the question now?
Tsansoterra
Tsansoterra el 18 de Feb. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (1)

David Hill
David Hill el 18 de Feb. de 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 comentario
Tsansoterra
Tsansoterra el 18 de Feb. de 2020
Editada: Tsansoterra el 18 de Feb. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by