2014-03-19 18 views
0

我試圖從爲每個力(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最小值?

回答

0

我的猜測是,你可能需要3個for循環外該位:

results_sorted=sortrows(results,1); %sorts factor of safety from min to max 
disp('   F   V    N'); 
disp(results_sorted); 
optimum=results_sorted(1,:) 

而且,我不知道你sort(F);環內達到的目標。

+0

我已將該部分移出for循環。似乎對結果沒有任何影響。 '排序(F);'用F(升序)排序結果,而不是安全容量(V)或安全係數(N)。在查看錶格時,可以更容易地確定哪個是最佳音量。 – user3062845

0

我覺得你的代碼需要兩個更改之前,你可以得到的V每個F中的最小值:

如果您使用的sortRows,應使用第二列(V)排序表,使最低V被放置在第一排。 results_sorted=sortrows(results,2);

您應該只對當前F的結果進行排序,因此,要麼爲每個F迭代清除變量「results」,要麼使用新變量results=[];。在排序行之前,一定要檢查「結果」是否爲空。

對於每個F迭代,變量「最優」現在具有最低的V值。

相關問題