Help executing calculation in for loop
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
David Hill
el 22 de Mzo. de 2021
Look at my answer below. You should not use symbolics. No loop is needed.
Respuesta aceptada
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
Más respuestas (0)
Ver también
Categorías
Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!