Help executing calculation in for loop

11 visualizaciones (últimos 30 días)
Serina Robbins
Serina Robbins el 22 de Mzo. de 2021
Comentada: Serina Robbins el 22 de Mzo. de 2021
Hello,
I am pretty new to matlab but have to use it for a class. I am currently trying to calculate the maximum force in a member using a moment equation for a range of angles.
I have created a for loop to run through my range of angles to calculate the component of the force in the y direction. When alpha (angle) is 0 the component will just be 1 instead of multiplied by the cosine of the angle because it will be entirely in the y direction.
I created a table to display the alpha angle and what the force should be muitiplied by to find the y component. So it has two columns and a bunch of rows.
I now need to be able to calculate the Force variable out of a moment equation using these values that I calculated. I wrote a program like this alreday that only calculates the component and force for one alpha angle instead of many using this:
ME = ((W*dW)-(FDC*cosd(myalpha)*dCB))==0;
FDC = round((solve(ME,FDC)),3);
Where W, dW, dCB, and myalpha are all known values.
Now I am trying to do that same thing but for a range. This is what my loop looks like:
for alpha = -43.43:1:43.43
if alpha == 0
FDCm = 1;
elseif alpha > 0
FDCm = cosd(alpha);
elseif alpha < 0
FDCm = cosd(alpha);
end
T = [T; alpha FDCm];
end
T
I need to do what I did for one angle for many angles and have it output into a table as well. I have tried many different things and keep getting errors no matter what I try. Any help is appreciated!
  5 comentarios
Serina Robbins
Serina Robbins el 22 de Mzo. de 2021
Okay thank you, I got that to work realizing I forgot to delete part of it the first time I tried to run it. Now that I have cosd(alpha) for all the angles I need in my range, how can I make a calculation using the new variable?
I tried doing this:
for alpha = -43.43:1:43.43
FDCm = cosd(alpha);
FDC = ((W*dW)/(FDCm*dCB));
end
But I keep getting this:
FDC =
(2251799813685248*W*dW)/(1658341119971255*dCB)
When I actually need FCD for every alpha value in my range.
Is there a way to do that calculation and put it as another column in my table? I can't get it to calculate anything but that one line.
David Hill
David Hill el 22 de Mzo. de 2021
Look at my answer below. You should not use symbolics. No loop is needed.

Iniciar sesión para comentar.

Respuesta aceptada

David Hill
David Hill el 22 de Mzo. de 2021
myalpha=-43.43:1:43.43;
for k=1:length(myalpha)
FDC(k)=round((W.*dW)/cosd(myalpha(k))./dCB,3);%I am assuming that W, dW, and dCB are all the same size or are scalar
end
  7 comentarios
David Hill
David Hill el 22 de Mzo. de 2021
[~,idx]=max(FDC);
alpha(idx)
Serina Robbins
Serina Robbins el 22 de Mzo. de 2021
That gives me on value but not the other, is there a way to give me the other?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by