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!