Effacer les filtres
Effacer les filtres

fminconを用い​たプログラムのpar​for導入方法

1 vue (au cours des 30 derniers jours)
Daichi
Daichi le 11 Jan 2024
Modifié(e) : Daichi le 13 Jan 2024
L12=2;
L23=1;
E=70;
I = 0.02;
A=0.2;
X1=30:0.5:150 ;
Y1=1.98:0.002:2.02;
Z1=0.99:0.001:1.01;
F0x1 = zeros(6,length(Z1),length(Y1),length(X1));
C1 = zeros(length(Z1),length(Y1),length(X1));
C2 = zeros(length(Z1),length(Y1),length(X1));
JF4 = zeros(length(Z1),length(Y1),length(X1));
global w
global q
global v
x = sym ('x',[1 6]);
for n=1:length(Z1)
L14=Z1(n);
for k=1:length(Y1)
L45=Y1(k);
for i=1:length(X1)
X=X1*(pi/180);
v=Z1(n);
q=Y1(k);
w=X(i);
AA1=[x(4);x(2)];
AAl1=[x(3);x(6)];
AAl2=[x(4);x(5)];
RR=[cos(X(i)),-sin(X(i));
sin(X(i)),cos(X(i))];
AA11=RR*AA1;
A14cd=RR*AAl1;
AA65=[x(6);(x(1)*sin(X(i)+x(5))+x(2)*cos(X(i)+x(5)))/(E*I)];
AA5b=RR*AA65;
J6=RR*AAl2;
BB65x=AA5b(1,1)+J6(1,1);
B14cdx=A14cd(1,1)+L23;
AA64=[x(6);(-x(1)*sin(X(i)+x(4))-x(2)*cos(X(i)+x(4)))];
AA4b=RR*AA64;
BB64x=AA4b(1,1)+J6(1,1);
BB11=AA11(1,1)+L12+L23;
nonlcon = @myf_fix;
AAA=1./(2*A*E)*(x(4)*x(1)+x(3)*x(6)+Y1(k)*x(4)*Z1(n)*x(5)+x(5)*x(1)*cos(X(i))-x(2)*sin(X(i)));
Aeq = [];
beq = [];
x0 = [0,0,0,L14,L45,L45];
opts = optimoptions(@fmincon,'Algorithm','sqp');
fun = @(y) double(subs(AAA,x,y));
lb = [-1000,-1000,X(i)-0.1,L14-0.5,L45-1,L45-1];
ub = [1000,1000,X(i)+1,L14+0.5,L45+1,L45+1];
ac = fmincon(fun,x0,[],[],[],[],lb,ub,nonlcon,opts);
disp(ac)
F0x1(:,i)=ac;
C1(n,k,i) = double(subs(x(1),x,ac));
C2(n,k,i) = double(subs(x(2),x,ac));
JF4(n,k,i)=(C1(n,k,i)^2+C2(n,k,i)^2)^0.5;
end
end
end
function [c,ceq] = myf_fix(x)
global q
global v
global w
L14=v;
L12=2;
L45=q;
L23=1;
E=70;
I = 0.02;
A=0.2;
AA1=[x(4);x(2)];
AAl1=[x(3);x(6)];
AAl2=[x(4);x(5)];
RR=[cos(w),-sin(w);
sin(w),cos(w)];
AA11=RR*AA1;
A14cd=RR*AAl1;
AA65=[x(6);(x(1)*sin(w+x(5))+x(2)*cos(w+x(5)))/(E*I)];
AA5b=RR*AA65;
J6=RR*AAl2;
BB65x=AA5b(1,1)+J6(1,1);
B14cdx=A14cd(1,1)+L23;
AA64=[x(6);(-x(1)*sin(w+x(4))-x(2)*cos(w+x(4)))];
AA4b=RR*AA64;
BB64x=AA4b(1,1)+J6(1,1);
BB11=AA11(1,1)+L12+L23;
c = [];
ceq(1) = BB65x-B14cdx;
ceq(2) = BB64x-BB11;
ceq(3) = x(4)-((L14)+x(1)*(L14)/(A*E));
ceq(4) = x(5)-(L45+(x(1)*cos(w)-x(2)*sin(w))*L45/(A*E));
end

Réponses (0)

Catégories

En savoir plus sur ソルバーベースの非線形最適化 dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!