필터 지우기
필터 지우기

Stopping a loop at the maximum value of y and finding the x from the maximum y

조회 수: 1 (최근 30일)
Hi everyone,
How can i stop the loop when i get the maximum M(i) and how do i know what is the value of the x (phi) for the maximum value of M?
Thank You.
b=300; %mm
d=400; %mm
fc=40; %Mpa
Ecm=22*(fc/10)^0.3*10^3; %Mpa
Es=200000; %Mpa
As=2400; %mm^2
fy=400; %Mpa
epsc1=min(2.8/1000,0.7*fc^0.31/1000);
epscu=3.5/1000;
k=1.05*Ecm*epsc1/fc;
epscmv = linspace(0.05, 3.5, 50)*1E-3;
for i=1:50(epscmv);
epscm = epscmv(i);
funC=@(epsc) (k*epsc/epsc1-(epsc/epsc1).^2)./(1+(k-2)*epsc/epsc1);
compression=@(c) b*fc*c/epscm*integral(funC,0,epscm)/1000;
tension=@(c) min(Es*(d-c)/c*epscm*As/1000,fy*As/1000);
c(i)=fsolve(@(c) compression(c)-tension(c),1);
funM=@(epsc)(k*epsc./epsc1-(epsc./epsc1).^2)./(1+(k-2)*epsc./epsc1).*(d-c(i)+(c(i)./epscm).*epsc);
M(i)=b*fc*c(i)/epscm*integral(funM,0,epscm)/1000000;
phi(i)=epscm/c(i);
end
Mmax=max(M(i))
plot(phi, M)
grid on
xlabel('phi [1/mm]')
ylabel('Moment [kNm]')

채택된 답변

David Hill
David Hill 2019년 11월 23일
b=300; %mm
d=400; %mm
fc=40; %Mpa
Ecm=22*(fc/10)^0.3*10^3; %Mpa
Es=200000; %Mpa
As=2400; %mm^2
fy=400; %Mpa
epsc1=min(2.8/1000,0.7*fc^0.31/1000);
epscu=3.5/1000;
k=1.05*Ecm*epsc1/fc;
epscmv = linspace(0.05, 3.5, 50)*1E-3;
for i=1:50(epscmv);
epscm = epscmv(i);
funC=@(epsc) (k*epsc/epsc1-(epsc/epsc1).^2)./(1+(k-2)*epsc/epsc1);
compression=@(c) b*fc*c/epscm*integral(funC,0,epscm)/1000;
tension=@(c) min(Es*(d-c)/c*epscm*As/1000,fy*As/1000);
c(i)=fsolve(@(c) compression(c)-tension(c),1);
funM=@(epsc)(k*epsc./epsc1-(epsc./epsc1).^2)./(1+(k-2)*epsc./epsc1).*(d-c(i)+(c(i)./epscm).*epsc);
M(i)=b*fc*c(i)/epscm*integral(funM,0,epscm)/1000000;
phi(i)=epscm/c(i);
end
[Mmax,idx]=max(M);%this is how you would get the max of M and the index at the maximum
phiAtmax=phi(idx);%using the index at maximum you can get the phi at the maximum
plot(phi, M)
grid on
xlabel('phi [1/mm]')
ylabel('Moment [kNm]')
  댓글 수: 3
David Hill
David Hill 2019년 11월 23일
If your function is smooth and has only one peak, then you can just check when the value is less than the previous value and break.
for i=1:50(epscmv);
epscm = epscmv(i);
funC=@(epsc) (k*epsc/epsc1-(epsc/epsc1).^2)./(1+(k-2)*epsc/epsc1);
compression=@(c) b*fc*c/epscm*integral(funC,0,epscm)/1000;
tension=@(c) min(Es*(d-c)/c*epscm*As/1000,fy*As/1000);
c(i)=fsolve(@(c) compression(c)-tension(c),1);
funM=@(epsc)(k*epsc./epsc1-(epsc./epsc1).^2)./(1+(k-2)*epsc./epsc1).*(d-c(i)+(c(i)./epscm).*epsc);
M(i)=b*fc*c(i)/epscm*integral(funM,0,epscm)/1000000;
phi(i)=epscm/c(i);
if M(i)<M(i-1)
break;
end
end
Shimon Katzman
Shimon Katzman 2019년 11월 23일
doesnt work
Attempted to access M(0); index must be a positive integer or logical.
Error in advencedconcrete32a (line 22)
if M(i)<M(i-1)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by