我試圖從爲每個力(F
)生成的表中提取V
的最小值,以便建立最佳結果,例如,對於F=5000
,V=0.06575
是最佳結果。
我希望能夠爲F
的每個實例顯示此值。我不太確定我的錯在哪裏。從表中提取並顯示結果MATLAB
%===========================================
%This Script calculates
%===========================================
%Parameter Values
%F:force (N)
%L1: Length of beam 1 (m)
%L2: Length of beam 2 (m)
%H: Height of beam 1 (m)
%h: Height of beam 2 (m)
%b: Cross section width (m)
%S: Yield strength (Pa)
%N: Factor of safety
%V:Volume of the beam (m^2)
%=========================================
clc %clear command window
clear all %clear all variables previously generated and stored in Matlab
format short g
L1=2;
L2=3;
b=0.05;
S=248;
K=1.42;
results=[];
optimalresults=[];
nd=3.6; %desired factor of safety calculated by group number
for F=5000:100:6000
for h=0.2:0.005:0.3 %loop of h
for H=0.2:0.005:0.3 % loop of H
M1=F*(L1+L2);
M2=F*L2;
I1=b*H^3/12;
I2=b*h^3/12;
Y1=H/2;
Y2=h/2;
Max_stress_1=M1*Y1/I1;
Max_stress_2=K*(M2*Y2/I2);
Max_total_stress=max(Max_stress_1,Max_stress_2);
Max_total_stress=Max_total_stress/1e6;
N=0.577*S/Max_total_stress;
%if N is greater than desired factor of safety then display results
if N >= nd
V=(b*L1*H)+(b*L2*h);
results=[results; F,V,N];sort(F);
end
end
end
results_sorted=sortrows(results,1); %sorts factor of safety from min to max
disp(' F V N');
disp(results_sorted);
optimum=results_sorted(1,:)
end
我有什麼改變顯示的V
每個F
最小值?
我已將該部分移出for循環。似乎對結果沒有任何影響。 '排序(F);'用F(升序)排序結果,而不是安全容量(V)或安全係數(N)。在查看錶格時,可以更容易地確定哪個是最佳音量。 – user3062845