% plot Fig. 4.3, FEA of Comp Mater Using ANSYS--Second Ed.
% Ever J. Barbero (c) 2007, 2013
clear all; close all;

Th=0.85*12 %10.8

lambda0= +(-209.04)  %216.66%  210.7879  
lambda1= -(-0) %-0.24389% 2.063125
lambda2= +(-0.2308) %0.3602 %0.36291%  0.368516

s_ini=-0.5*Th;
s_fin=1.5*Th;

s_inc = [s_ini:0.1:s_fin];
P_inc = lambda0 + lambda1 .* s_inc + lambda2.*s_inc.^2;

s = 1*Th;

P = lambda0 + lambda1*s + lambda2*s^2;
Po= lambda0;

s1_inc = [0,0]; %[0.2,0.2];
P1_inc = [0,Po];

so_inc = [0:1:Th/2];
Po_inc = lambda0 .* so_inc./so_inc;

% Ansys results OPEN I/0 FILES
n_file = 'FEAcomp_Ex402_conti_225' % series name
fidinp = fopen([n_file,'.txt'],'r');   
results = (fscanf(fidinp,'%g %g',[2 inf]));
fclose(fidinp);

results(1,:)=(results(1,:)-1)*(225)

linetxt1 = ['N_{s=Th}=' num2str(-int32(P)) ' N/mm  \rightarrow  ']
linetxt2 = [' \leftarrow N_{cr}=' num2str(-int32(Po)) ' N/mm']
linewth  = 2.8

figure1 = figure
plot(s_inc,-P_inc,'k','LineWidth',linewth)
xlabel('s [mm]','Fontsize',16);ylabel('N [N/mm]','Fontsize',16);
hold on
plot(s1_inc,-P1_inc,'k','LineWidth',linewth)
plot(so_inc,-Po_inc,'k-.','LineWidth',1)
text(s,-P,linetxt1,'HorizontalAlignment','right','Fontsize',16)
text(Th/2,-Po,linetxt2,'HorizontalAlignment','left','Fontsize',16)
axis([s_ini s_fin 0 -min(P_inc)]) 

set(gca,'Fontsize',16);

plot(s,-P,'ks','MarkerSize',10,'LineWidth',2)
plot(0,-Po,'ks','MarkerSize',10,'LineWidth',2)
%plot(results(2,:),results(1,:),'r')
hold off

saveas(figure1,['Fig4_3'],'pdf');
