Help executing calculation in for loop
이전 댓글 표시
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
Jan
2021년 3월 22일
Whenever you mention an error in the forum, post a copy of the error message.
I do not understand, what you are asking for. The loop can be simplified to:
alpha = (-43.43:43:43).';
T = [alpha, cosd(alpha)];
There is no need for the IF branchs.
Serina Robbins
2021년 3월 22일
Jan
2021년 3월 22일
I mention it again:
if alpha == 0
FDCm = 1;
elseif alpha > 0
FDCm = cosd(alpha);
elseif alpha < 0
FDCm = cosd(alpha);
end
is exactly the same as:
FDCm = cosd(alpha);
Find out, which of the variables is a struct, e.g. by uisng the debugger and the command whos
Serina Robbins
2021년 3월 22일
David Hill
2021년 3월 22일
Look at my answer below. You should not use symbolics. No loop is needed.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!