matlab神经网络模拟圆棒表面裂纹拓展

clear all; clc;
plot_api;
del_a_B = 100;
a_ratio_d = 0;
A = 1000; B = 12000;
fun_2d = @(p,x) (x(:,1).^2)/(p(1)^2) + (x(:,2).^2)/(p(2)^2) - 1 ; %双参数拟合
p0= [ 3000 5000 ];
D = 12000;
m = 3.086;
x_ratio_h = [ 0 0.167 0.333 0.5 0.667 0.833 1 ];
new_mat = [ ];
while a_ratio_d < 0.7
    theta_lim = fsolve(@(theta)B^2 * cos(theta).^2 + A^2 * sin(theta).^2 - 12000 * A * sin(theta), [ pi/4 3*pi/4 ] );
    theta_fitted = theta_lim(1,1) :pi/200: theta_lim(1,2) + pi/400;
    x_lim = B * cos(theta_lim(1,1));
    clear theta_lim;
    x_fitted = B * cos(theta_fitted);
    y_fitted = A * sin(theta_fitted);
    plot(x_fitted, y_fitted);
    clear x_fitted y_fitted theta_fitted;
    hold on;
    depth = A/D ; morph = A/B;
    stress_intensity_factor = fitted_test_1([depth morph]);
    clear depth morph
    for i = 1 : 7
        del_a_i = del_a_B * (stress_intensity_factor(i,1)/stress_intensity_factor(1,1))^m;
        x_pos = x_lim * x_ratio_h(1, i);
        y_pos = A * ( 1 - x_pos^2 / B^2)^0.5;
        new_mat(i,1) = x_pos + A^2 * x_pos * del_a_i / ( A^4 * x_pos^2 + B^4 * y_pos^2 )^0.5;
        new_mat(i,2) = y_pos + B^2 * y_pos * del_a_i / ( A^4 * x_pos^2 + B^4 * y_pos^2 )^0.5;
        clear x_pos y_pos del_a_i;
    end
    clear stress_intensity_factor x_lim;
    p = nlinfit(new_mat,zeros(size(new_mat,1),1),fun_2d,p0);
    p0 =p;
    B = abs(p(1)); A = abs(p(2)); 
    a_ratio_d = A/D;
end
xlabel('\mu m'); ylabel('\mu m');
set(gcf,'Position',[100 100 500 500]);
title('圆棒裂纹扩展模拟');
saveas(gcf,['D:\SJTU大三(上)总\EM216力学创新实验\研究进度\第15周_论文撰写\figures\extension_simulation.png']);
clear del_a_B a_ratio_d B A fun_2d p0 D m x_ratio_h new_mat i p;
function [Y,Xf,Af] = myNeuralNetworkFunction(X,~,~)
%MYNEURALNETWORKFUNCTION neural network simulation function.
%
% Auto-generated by MATLAB, 13-Dec-2020 19:17:37.
%
% [Y] = myNeuralNetworkFunction(X,~,~) takes these arguments:
%
%   X = 1xTS cell, 1 inputs over TS timesteps
%   Each X{1,ts} = 2xQ matrix, input #1 at timestep ts.
%
% and returns:
%   Y = 1xTS cell of 1 outputs over TS timesteps.
%   Each Y{1,ts} = 7xQ matrix, output #1 at timestep ts.
%
% where Q is number of samples (or series) and TS is the number of timesteps.

%#ok<*RPMT0>

% ===== NEURAL NETWORK CONSTANTS =====

% Input 1
x1_step1.xoffset = [0.067;0];
x1_step1.gain = [2.72851296043656;2];
x1_step1.ymin = -1;

% Layer 1
b1 = [2.798270549872531987;2.0100510141885101767;-0.37466416782238459726;-0.33268390255902330344;1.2956788533607312974;0.86920105444564277342;-0.010602563409371160846;1.4157716494802208285;-0.74601373963357464625;3.4314132442351508168];
IW1_1 = [-1.0206775413512363393 -1.2084158679086436372;-1.9041284568288459056 0.18104797124476898484;-0.25096046414452144457 1.1278203170188603188;1.8067657311405735943 0.25579664505562865751;-0.099876243854055718474 1.0855638192919201401;-1.6250124086354347241 0.66445759983161589712;1.149125394210181561 -1.1460544076743071074;1.9586964028555948758 0.96796916637917385096;-0.58144522186048086532 1.2036586184192701321;1.1997148243051003469 3.1295607556929798676];

% Layer 2
b2 = [-0.29177092745740496049;-0.26968685508346595947;-0.19819382002138918875;-0.067461092969405875297;0.16557456551589308513;0.41670093491218473947;0.93699908252943664433];
LW2_1 = [0.72935741133616871501 -1.1335039576266603412 -0.18750176530311565837 0.12429821706587920738 0.18886405701656622247 -0.19063160494828884639 0.058672267132489151764 0.035550267697781315346 0.052147150078221155001 -0.028094911105505829957;0.70662380610605612929 -1.1333481580981157322 -0.16407433071256485868 0.12115407940046157842 0.19191066854893196192 -0.19570955460409786286 0.062657734025100497721 0.033216883296529817193 0.034136553607176156611 -0.027793709651298726532;0.63278867653577552943 -1.1332307746322503039 -0.090237071729924081542 0.11097715634624664982 0.2004288304266720333 -0.2112213011245518135 0.075434798626401872168 0.025748509571258869355 -0.022463556272241304995 -0.026054765284314027746;0.49897622285728310265 -1.1334708188089723802 0.04377605264525251394 0.093174245670640185035 0.21440718379751699807 -0.23819155175985931572 0.097750660162704436362 0.012804255426597127912 -0.12529785966103790251 -0.022955582368242109098;0.26464093455027082324 -1.140263080512227134 0.26465213201183590552 0.063829901388267842877 0.23259268921920064899 -0.27890892651947313263 0.13248816310140026919 -0.0067434941977890803036 -0.29507976705207700219 -0.017340444826024717373;0.013122289285899573635 -1.1492652696918930211 0.60688859110772008787 0.026551159356929247835 0.24644787686244462588 -0.32985754762141272778 0.18064564396203985908 -0.032380548951814122627 -0.5560675847909190006 -0.0066425782672229613177;-0.67964612303598359588 -1.0609982065833454268 0.55073431814094686576 0.01876584427292667806 0.39290217602413085585 -0.31352944255675319063 0.21626111787925492158 -0.02464056630985255944 -0.49116178434460661117 -0.028847577151960592662];

% Output 1
y1_step1.ymin = -1;
y1_step1.gain = [0.392387679026879;0.392927308447937;0.394555139080687;0.397456279809221;0.401687085760193;0.405761817812944;0.373761913660998];
y1_step1.xoffset = [0.626;0.626;0.627;0.627;0.628;0.62;0.506];

% ===== SIMULATION ========

% Format Input Arguments
isCellX = iscell(X);
if ~isCellX
    X = {X};
end

% Dimensions
TS = size(X,2); % timesteps
if ~isempty(X)
    Q = size(X{1},2); % samples/series
else
    Q = 0;
end

% Allocate Outputs
Y = cell(1,TS);

% Time loop
for ts=1:TS
    
    % Input 1
    Xp1 = mapminmax_apply(X{1,ts},x1_step1);
    
    % Layer 1
    a1 = tansig_apply(repmat(b1,1,Q) + IW1_1*Xp1);
    
    % Layer 2
    a2 = repmat(b2,1,Q) + LW2_1*a1;
    
    % Output 1
    Y{1,ts} = mapminmax_reverse(a2,y1_step1);
end

% Final Delay States
Xf = cell(1,0);
Af = cell(2,0);

% Format Output Arguments
if ~isCellX
    Y = cell2mat(Y);
end
end

% ===== MODULE FUNCTIONS ========

% Map Minimum and Maximum Input Processing Function
function y = mapminmax_apply(x,settings)
y = bsxfun(@minus,x,settings.xoffset);
y = bsxfun(@times,y,settings.gain);
y = bsxfun(@plus,y,settings.ymin);
end

% Sigmoid Symmetric Transfer Function
function a = tansig_apply(n,~)
a = 2 ./ (1 + exp(-2*n)) - 1;
end

% Map Minimum and Maximum Output Reverse-Processing Function
function x = mapminmax_reverse(y,settings)
x = bsxfun(@minus,y,settings.ymin);
x = bsxfun(@rdivide,x,settings.gain);
x = bsxfun(@plus,x,settings.xoffset);
end
figure(1);
ha=gca;
set(ha,'xlim',[-6000,6000]);
set(ha,'ylim',[0,12000]);
hold on;
clear ha;
r=6000;
theta=0:pi/100:2*pi;
x=0+r*cos(theta);
y=6000+r*sin(theta);
plot(x,y);
hold on;
clear x y r theta;
clear all; clc;
plot_api;
S1 = xlsread('D:\SJTU大三(上)总\EM216力学创新实验\研究进度\第7周_直接椭圆拟合\原始数据(修改).xlsx','4#9+0Nm');
min_1 = 1;
max_1 = 5; 
for jj_1 = min_1 : max_1
    xs_1 = S1(:,2*jj_1-1);
    xs_1 = rmmissing(xs_1);
    ys_1 = S1(:,2*jj_1);
    ys_1 = rmmissing(ys_1);
    scatter(xs_1,ys_1,[],'.');
    hold on;
end
clear min_1max_1 jj_1 xs_1 ys_1;
del_a_B = 100;
a_ratio_d = 0;
fun_2d = @(p,x) (x(:,1).^2)/(p(1)^2) + (x(:,2).^2)/(p(2)^2) - 1 ; %双参数拟合
p0= [ 3000 5000 ];
D = 12000;
m = 3.086;
x_ratio_h = [ 0 0.167 0.333 0.5 0.667 0.833 1 ];
new_mat = [ ];
x_1 = horzcat(S1(:,1),S1(:,2));
p = nlinfit(x_1,zeros(size(x_1,1),1),fun_2d,p0);
p0 = p;
B = abs(p(1)); A = abs(p(2)); 
while a_ratio_d < 0.7
    theta_lim = fsolve(@(theta)B^2 * cos(theta).^2 + A^2 * sin(theta).^2 - 12000 * A * sin(theta), [ pi/4 3*pi/4 ] );
    theta_fitted = theta_lim(1,1) :pi/200: theta_lim(1,2) + pi/400;
    x_lim = B * cos(theta_lim(1,1));
    clear theta_lim;
    x_fitted = B * cos(theta_fitted);
    y_fitted = A * sin(theta_fitted);
    plot(x_fitted, y_fitted);
    clear x_fitted y_fitted theta_fitted;
    hold on;
    depth = A/D ; morph = A/B;
    stress_intensity_factor = fitted_test_1([depth morph]);
    clear depth morph
    for i = 1 : 7
        del_a_i = del_a_B * (stress_intensity_factor(i,1)/stress_intensity_factor(1,1))^m;
        x_pos = x_lim * x_ratio_h(1, i);
        y_pos = A * ( 1 - x_pos^2 / B^2)^0.5;
        new_mat(i,1) = x_pos + A^2 * x_pos * del_a_i / ( A^4 * x_pos^2 + B^4 * y_pos^2 )^0.5;
        new_mat(i,2) = y_pos + B^2 * y_pos * del_a_i / ( A^4 * x_pos^2 + B^4 * y_pos^2 )^0.5;
        clear x_pos y_pos del_a_i;
    end
    clear stress_intensity_factor x_lim;
    p = nlinfit(new_mat,zeros(size(new_mat,1),1),fun_2d,p0);
    p0 =p;
    B = abs(p(1)); A = abs(p(2)); 
    a_ratio_d = A/D;
end
xlabel('\mu m'); ylabel('\mu m');
set(gcf,'Position',[100 100 500 500]);
clear del_a_B a_ratio_d B A fun_2d p0 D m x_ratio_h new_mat i p;
clear all; clc;
plot_api;
S2 = xlsread('D:\SJTU大三(上)总\EM216力学创新实验\研究进度\第7周_直接椭圆拟合\原始数据(修改).xlsx','5#9+0Nm');
min_2 = 1;
max_2 = 7; 
for jj_2 = min_2 : max_2
    xs = S2(:,2*jj_2-1);
    xs = rmmissing(xs);
    ys = S2(:,2*jj_2);
    ys = rmmissing(ys);
    scatter(xs,ys,80,'.');
    hold on;
end
clear min_2 max_2 jj_2 xs ys;
del_a_B = 300;
a_ratio_d = 0;
A = 1000; B = 12000;
fun_2d = @(p,x) (x(:,1).^2)/(p(1)^2) + (x(:,2).^2)/(p(2)^2) - 1 ; %双参数拟合
p0= [ 3000 5000 ];
D = 12000;
m = 1.3;
x_ratio_h = [ 0 0.167 0.333 0.5 0.667 0.833 1 ];
new_mat = [ ];
while a_ratio_d < 0.75
    theta_lim = fsolve(@(theta)B^2 * cos(theta).^2 + A^2 * sin(theta).^2 - 12000 * A * sin(theta), [ pi/4 3*pi/4 ] );
    theta_fitted = theta_lim(1,1) :pi/200: theta_lim(1,2) + pi/400;
    x_lim = B * cos(theta_lim(1,1));
    clear theta_lim;
    x_fitted = B * cos(theta_fitted);
    y_fitted = A * sin(theta_fitted);
    plot(x_fitted, y_fitted);
    clear x_fitted y_fitted theta_fitted;
    hold on;
    depth = A/D ; morph = A/B;
    stress_intensity_factor = fitted_test_1([depth morph]);
    clear depth morph
    for i = 1 : 7
        del_a_i = del_a_B * (stress_intensity_factor(i,1)/stress_intensity_factor(1,1))^m;
        x_pos = x_lim * x_ratio_h(1, i);
        y_pos = A * ( 1 - x_pos^2 / B^2)^0.5;
        new_mat(i,1) = x_pos + A^2 * x_pos * del_a_i / ( A^4 * x_pos^2 + B^4 * y_pos^2 )^0.5;
        new_mat(i,2) = y_pos + B^2 * y_pos * del_a_i / ( A^4 * x_pos^2 + B^4 * y_pos^2 )^0.5;
        clear x_pos y_pos del_a_i;
    end
    clear stress_intensity_factor x_lim;
    p = nlinfit(new_mat,zeros(size(new_mat,1),1),fun_2d,p0);
    p0 =p;
    B = abs(p(1)); A = abs(p(2)); 
    a_ratio_d = A/D;
end
xlabel('\mu m'); ylabel('\mu m');
set(gcf,'Position',[0 0 800 800]);
title('2号圆棒裂纹扩展模拟对比');
saveas(gcf,['D:\SJTU大三(上)总\EM216力学创新实验\研究进度\第15周_论文撰写\figures\extension_simulation_rod_2nd.png']);
clear del_a_B a_ratio_d B A fun_2d p0 D m x_ratio_h new_mat i p;
clear all; clc;
plot_api;
S1 = xlsread('D:\SJTU大三(上)总\EM216力学创新实验\研究进度\第7周_直接椭圆拟合\原始数据(修改).xlsx','4#9+0Nm');
min_1 = 1;
max_1 = 5; 
for jj_1 = min_1 : max_1
    xs_1 = S1(:,2*jj_1-1);
    xs_1 = rmmissing(xs_1);
    ys_1 = S1(:,2*jj_1);
    ys_1 = rmmissing(ys_1);
    scatter(xs_1,ys_1,80,'.');
    hold on;
end
clear min_1max_1 jj_1 xs_1 ys_1;
del_a_B = 300;
a_ratio_d = 0;
A = 1000; B = 12000;
fun_2d = @(p,x) (x(:,1).^2)/(p(1)^2) + (x(:,2).^2)/(p(2)^2) - 1 ; %双参数拟合
p0= [ 3000 5000 ];
D = 12000;
m = 1.3;
x_ratio_h = [ 0 0.167 0.333 0.5 0.667 0.833 1 ];
new_mat = [ ];
while a_ratio_d < 0.75
    theta_lim = fsolve(@(theta)B^2 * cos(theta).^2 + A^2 * sin(theta).^2 - 12000 * A * sin(theta), [ pi/4 3*pi/4 ] );
    theta_fitted = theta_lim(1,1) :pi/200: theta_lim(1,2) + pi/400;
    x_lim = B * cos(theta_lim(1,1));
    clear theta_lim;
    x_fitted = B * cos(theta_fitted);
    y_fitted = A * sin(theta_fitted);
    plot(x_fitted, y_fitted);
    clear x_fitted y_fitted theta_fitted;
    hold on;
    depth = A/D ; morph = A/B;
    stress_intensity_factor = fitted_test_1([depth morph]);
    clear depth morph
    for i = 1 : 7
        del_a_i = del_a_B * (stress_intensity_factor(i,1)/stress_intensity_factor(1,1))^m;
        x_pos = x_lim * x_ratio_h(1, i);
        y_pos = A * ( 1 - x_pos^2 / B^2)^0.5;
        new_mat(i,1) = x_pos + A^2 * x_pos * del_a_i / ( A^4 * x_pos^2 + B^4 * y_pos^2 )^0.5;
        new_mat(i,2) = y_pos + B^2 * y_pos * del_a_i / ( A^4 * x_pos^2 + B^4 * y_pos^2 )^0.5;
        clear x_pos y_pos del_a_i;
    end
    clear stress_intensity_factor x_lim;
    p = nlinfit(new_mat,zeros(size(new_mat,1),1),fun_2d,p0);
    p0 =p;
    B = abs(p(1)); A = abs(p(2)); 
    a_ratio_d = A/D;
end
xlabel('\mu m'); ylabel('\mu m');
set(gcf,'Position',[0 0 800 800]);
title('1号圆棒裂纹扩展模拟对比');
saveas(gcf,['D:\SJTU大三(上)总\EM216力学创新实验\研究进度\第15周_论文撰写\figures\extension_simulation_rod_1st.png']);
clear del_a_B a_ratio_d B A fun_2d p0 D m x_ratio_h new_mat i p;

 

 

 

 

 

 

 

 

 

 

Trifun = @(p,x) ( x(:,1) * cos(p(3)) - x(:,2) * sin(p(3)) + 6000 * sin(p(3)) / 2 ).^2 / p(1)^2 + ( x(:,1) * sin(p(3)) + x(:,2) * cos(p(3))  + 6000 * (1 - cos(p(3)) ) / 2 ).^2 / p(2)^2 - 1;
x = horzcat(xs,ys);
p = nlinfit(x,zeros(size(x,1),1),Trifun,p0);
p0 = p;
scatter(xs,ys,[],'.');
%plot(x(:,1),x(:,2),'ro');
hold on;
A = p(1); B = p(2) ; C = p(3) ; 
Trifun11 = @(x,y) ( x * cos(C) - y * sin(C) + 6000 * sin(C) / 2 ).^2 / A^2 + ( x * sin(C) + y * cos(C)  + 6000 * (1 - cos(C) ) / 2 ).^2 / B^2 - 1 ; %Trifun的参数确定隐函数
fimplicit(Trifun11);
hold on;
clear x xs ys p Trifun Trifun11;
import_depth_para;
D = 12000; R = 6000;
arc_length = []; depth = [];
for i = 1 : 5
    A = rod_1st_mat(i,2);
    B = rod_1st_mat(i,1);
    theta_1 = fsolve(@(theta_1) (R * cos(theta_1))^2 / B^2 + (R + R * sin(theta_1))^2 / A^2 - 1, -pi/4);
    arc_length(1,i) = R * (theta_1 + pi/2) / D;
    depth(1,i) = A / D;
    clear A B theta_1;
end
for i = 6 : 12
    A = rod_2nd_mat(i-5,2);
    B = rod_2nd_mat(i-5,1);
    theta_1 = fsolve(@(theta_1) (R * cos(theta_1))^2 / B^2 + (R + R * sin(theta_1))^2 / A^2 - 1, -pi/4);
    arc_length(1,i) = R * (theta_1 + pi/2) / D;
    depth(1,i) = A / D;
    clear A B theta_1;
end
clear i D R rod_1st_mat rod_2nd_mat;
fun_line = @(p,x) p(1) + p(2) * (x(1,:));
p0 = [-0.0415754393664210,0.823310617153332];
p = nlinfit(arc_length, depth, fun_line, p0);
figure(1);
set(gca,'xlim',[0.3,1],'ylim',[0.2,0.8]);
hold on;
grid on;
scatter(arc_length,depth,[],'.');
hold on; %0.425 0.884
arc_fitted = 0.425 : 0.005 : 0.89;
depth_fitted = p(1) + p(2) * arc_fitted;
plot(arc_fitted, depth_fitted);
xlabel('s/D'); ylabel('a/D ');
title('圆棒裂纹相对深度与相对半弧长的关系');
saveas(gcf,['D:\SJTU大三(上)总\EM216力学创新实验\研究进度\第15周_论文撰写\figures\s_D_a_D.png']);
arc_length_dim = 12000 * arc_length';
xlswrite('D:\SJTU大三(上)总\EM216力学创新实验\研究进度\第15周_论文撰写\tables\arc_length.xlsx',arc_length_dim,'Sheet1');
clear arc_fitted depth_fitted p0 fun_line;

clear all; clc;
rod_1st_mat = xlsread('D:\SJTU大三(上)总\EM216力学创新实验\研究进度\第15周_论文撰写\tables\rod_1st.xlsx','Sheet1');
rod_2nd_mat = xlsread('D:\SJTU大三(上)总\EM216力学创新实验\研究进度\第15周_论文撰写\tables\rod_2nd.xlsx','Sheet1');
rod_2nd_mat(1:5,:) = [];
clear all; clc;
S1 = xlsread('D:\SJTU大三(上)总\EM216力学创新实验\研究进度\第10周_三参数拟合\data_test_1.xlsx','Sheet1');
figure(1);
ha=gca;
set(ha,'xlim',[-6000,6000]);
set(ha,'ylim',[0,12000]);
clear ha;
r=6000;
theta=0:pi/100:2*pi;
x=0+r*cos(theta);
y=6000+r*sin(theta);
plot(x,y);
hold on;
clear x y r theta;
min = 13;
max = 17; 
p0=[ 6710 4920 0 ];
for j = min : max
    xs = S1(:,2*j-1);
    xs = rmmissing(xs);
    ys = S1(:,2*j);
    ys = rmmissing(ys);
    fit_it_3;
    major_axis_list(j,1) = A;
    clear A;
    minor_axis_list(j,1) = B;
    clear B;
    theta_list(j,1) = C;
    clear C;
end
clear j min max p0;
xlabel('\mu m'); ylabel('\mu m');
title('3号圆棒裂纹前缘拟合曲线');
set(gcf,'Position',[100 100 500 500]);
saveas(gcf,['D:\SJTU大三(上)总\EM216力学创新实验\研究进度\第15周_论文撰写\figures\rod_3rd.png']);

おすすめ

転載: blog.csdn.net/joshua_shi_t/article/details/121503759