Help executing calculation in for loop

조회 수: 11 (최근 30일)
Serina Robbins
Serina Robbins 2021년 3월 22일
댓글: Serina Robbins 2021년 3월 22일
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
Serina Robbins
Serina Robbins 2021년 3월 22일
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 2021년 3월 22일
Look at my answer below. You should not use symbolics. No loop is needed.

댓글을 달려면 로그인하십시오.

채택된 답변

David Hill
David Hill 2021년 3월 22일
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
David Hill
David Hill 2021년 3월 22일
[~,idx]=max(FDC);
alpha(idx)
Serina Robbins
Serina Robbins 2021년 3월 22일
That gives me on value but not the other, is there a way to give me the other?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by