How can I write a multifunctions to test exhaustive search method
    조회 수: 7 (최근 30일)
  
       이전 댓글 표시
    
for example I have 5000*b*d<=36000 and (1.65*10^4)*b*d^2 <=84*10^6 and I want to calculate the new b and d which helps get min cross sectional area but it only works once for one equation .
A=1000;
for b=0:0.01:25
    for d=0:0.01:50
        %bending stress
        if (1.65*10^4)*b*d^2 <=84*10^6
            X=(1.65*10^4)*b*d^2;
            if A<X
                A=X;
                bo=b;
                do=d;
                %check on the constraint
                b>=0    ;
                d>=0 ;
                d-2*b<=0;
                % shear stress
                if 5000*b*d<=36000
                    Y=(5000)*b*d;
                    if A<Y
                        A=Y;
                        bo=b;
                        do=d;
                    end
                end
            end
        end
    end
end 
bo
do
A=bo*do
댓글 수: 3
  Mathieu NOE
      
 2021년 1월 12일
				hello 
I may be wrong, but can we do something more straigthforward using meshgrid ? 
like : 
A=1000;
b=0:0.01:25;
d=0:0.01:50;
[bb,dd] = meshgrid(b,d);
% criteria 1 , find b,d pairs that fullfill 5000*b*d<=36000 (or  b*d<36/5)
prod1 = bb.*dd;
threshold1 = 36/5;
% criteria 2 , find b,d pairs that fullfill (1.65*10^4)*b*d^2 <=84*10^6 (or  b*d^2<= 84*10^6 / (1.65*10^4) )
prod2 = bb.*(dd.^2);
threshold2 = 84*10^6 / (1.65*10^4);
ind = find(prod1<threshold1 & prod2<threshold2);
bb_sol = bb(ind);
dd_sol = dd(ind);
plot(bb_sol,dd_sol,'+');grid 
xlabel('b');
ylabel('d');
답변 (1개)
  Zuber Khan
 2024년 9월 20일
        Hi,
Based on my understanding of the question, it seems you are looking for a function based design of your exhaustive search problem. I have implemented the same and you can check it as follows.
function [bo, do, A] = evaluateCrossSection()
    % Initialize variables
    A = 1000; % Area
    % Iterate over possible values of b and d
    for b = 0:0.01:25
        for d = 0:0.01:50
           % Bending stress constraint
           if bendingstress(b,d)
           % Area check    
            if AreaCheck(A,b,d)
                A= (1.65*10^4)*b*d^2;
                bo = b;
                do = d;
            % Check for valid values    
            if isValid(b, d)
                currentArea = b * d;
                % Update area if less than a certain value
                if  A < 5000*currentArea
                    A = 5000*currentArea;
                    bo = b;
                    do = d;
                end
            end
            end
           end
        end
    end
    % Display the results
    fprintf('Optimal b: %.2f\n', bo);
    fprintf('Optimal d: %.2f\n', do);
    fprintf('Minimum Cross-Sectional Area: %.2f\n', bo*do);
end
function valid = isValid(b, d)
    % Check all constraints
    valid = (1.65 * 10^4) * b * d^2 <= 84 * 10^6 && ...
            5000 * b * d <= 36000 && ...
            b >= 0 && ...
            d >= 0 && ...
            d - 2 * b <= 0;
end
function valid = AreaCheck(A,b,d)
    % Check all constraints
    valid = A<(1.65*10^4)*b*d^2;
end
function valid = bendingstress(b,d)
    % Check all constraints
    valid = (1.65*10^4)*b*d^2 <=84*10^6;
end
Based on the constraints provided, it generates the following output:
Optimal b: 3.52
Optimal d: 38.03
Minimum Cross-Sectional Area: 133.87
I have checked for each iteration and the magnitude of cross sectional area is changing before it attains the final value. You can modify the above code and pass the equations as arguement to make it more generic.
In case you are not getting the desired result, I would suggest you to carefully examine the constraints involved as well as the area update loop to check for any missing information.
I hope it will address your concerns.
Regards,
Zuber
댓글 수: 0
참고 항목
카테고리
				Help Center 및 File Exchange에서 Direct Search에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



