append data in the array using for loop

9 views (last 30 days)
dharmin
dharmin on 23 Jun 2023
Commented: AL on 23 Jun 2023
I would greatly appreciate some assistance. Currently, I am working on finding an optimal solution that satisfies certain conditions. My objective is to solve a composite laminate problem by iteratively adjusting the number of layers. If the existing number of layers does not meet the design specifications, my plan is to add two more layers of the same orientation. I will then perform the analysis again to determine if this modified configuration meets the design requirements. However, I am unsure of how to add data into the array within the for loop. Any guidance on this matter would be highly appreciated.
format short
SLp=1448; SLn=1172; STp=48.3; STn=248; SLT=62.1;
E1=142.9;
E2=9.79;
G=6.53;
P12=0.26;
Nx=2582;
Nxy=5000;
Mxy=0;
min_tsai=1.000;
ply_combination=zeros(1,6);
tic % to calculate time to complete the operation
K =1000;
for i = 1:K
for j=-90:1:90 %% if j =65
for k=-j %%in that case k = -65
Here theta is represented by j and k where as n is donoted by i in the code, s means symmetric layup.
% main iteration code begins
[stresses,abd]= abbd([i j k],2,E1,E2,G,P12,Nx,Mxy,Nxy);
[tsai,matrix]=avg_tsai(stresses,SLp,SLn,STp,STn,SLT);
if tsai<min_tsai
min_tsai=tsai;
ply_combination_=[j k]; %% i want to add here something like this [j k j k] using interation value of i.
ply_combination = [ply_combination_, fliplr(ply_combination_) ] % creating symmatrical layup on which the analysis has to be done
end
% end of main iteration code
end
end
end
time=toc;
fileID=fopen('Tsai_Data.txt','a');
fprintf(fileID,'\n\n%s\t','Ply Combination : ');
for i=1:6
fprintf(fileID,'%d\t',ply_combination(i));
end
fprintf(fileID,'\n%s %6.6f','Minimum Average Tsai = ',min_tsai);
fprintf(fileID,'\n%s %6.6f','Time Taken = ',time);
fclose(fileID);
  3 Comments
dharmin
dharmin on 23 Jun 2023
Indeed, even i am currently trying to figure out the logic, since I have to find one set of angles such as [+46,-46]6, where 6 reprsent the number of layers. the question i have post earlier above for that I have changed: i think i have to store each set of values that meet the criteria and then sort out the best solutions from that set.
ply_combination_ = repmat([j -j], 1, i-1); % Repeat [j -j] i times
ply_combination = [ply_combination_, fliplr(ply_combination_)];
However, as you mentioned earlier this program is only running for i = 1:k and not changing the value of j. resulting in bug.
@dpb thank you so much for helping me.
AL
AL on 23 Jun 2023

What do you think of this logic @dpb % Set the failure criteria failure_criteria = 0.5; % Example value, modify as per your requirements

% Initialize variables i = 1; j_range = -90:1:90; % Range of j values from -90 to +90 degrees num_layers = [];

% Loop until the failure criteria are satisfied while isempty(num_layers) for j = j_range k = -j; % j = -k

        % Check the failure condition
        if checkFailureCondition(i, j, k, failure_criteria)
            num_layers = i;
            break;
        end
    end
    % If failure condition not satisfied, increment i and check again
    if isempty(num_layers)
        i = i + 1;
    end
end

% Display the minimal number of layers required disp(['Minimal number of layers required: ', num2str(num_layers)]);

% Function to check the failure condition function isFailed = checkFailureCondition(i, j, k, failure_criteria) % Calculate the failure condition based on i, j, k % Implement your own logic here % You can use the variables i, j, and k to calculate the failure condition % Return true if the condition is satisfied, false otherwise

    % Example failure condition:
    isFailed = abs(j - k) > failure_criteria;
end

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!