How to display fit equation on plot?
조회 수: 70 (최근 30일)
이전 댓글 표시
Hello all,
I have written code that creates a power fit to some data. The code is :
p=polyfit(log(pla_strain),log(pla_stress),1);
m=p(1);
b=exp(p(2));
yy=b.*(pla_strain).^m;
I think plot the data with the fit as follows:
loglog(pla_strain,pla_stress,'LineWidth',4)
hold on
plot(pla_strain,yy,'r--','LineWidth',2)
axis([.001 .1 40 100])
hold off
My problem is I am trying to display the equation of the fit on the plot. The equation is of the form y=b*x^m where b and m are the two coefficients from the polyfit. I would like to display this equation in the same location of the plot every time, which would ideally be towards the top center.
Thanks
댓글 수: 0
답변 (4개)
G A
2013년 11월 18일
txt1='b*x^m';
yL=get(gca,'YLim');
xL=get(gca,'XLim');
text((xL(1)+xL(2))/2,yL(2),txt1,...
'HorizontalAlignment','left',...
'VerticalAlignment','top',...
'BackgroundColor',[1 1 1],...
'FontSize',12);
댓글 수: 0
Image Analyst
2013년 11월 18일
You're going to have to convert the x and yy back into pla_strain and pla_stress so you can plot them
x = log(pla_strain);
pla_strain_fitted = exp(x);
yy = m .* x + b; % This equals log(pla_stress)
pla_stress_fitted = exp(yy);
loglog(pla_strain_fitted, pla_stress_fitted, 'LineWidth',4)
댓글 수: 0
GILBERT ALVIOLA
2017년 7월 24일
Something like this... where x and y specifies the position
txt1 = ['y = (' num2str(m) ')x + (' num2str(a) ')']; text(x, y, txt1);
댓글 수: 0
VBBV
2021년 10월 28일
편집: VBBV
2021년 10월 28일
stress = [0;0.0464;0.1940;0.4962;0.5040;0.5566;0.6040;0.6260;0.6240;0.6100;0.5880;0.5720]; % e.g values
strain = [0;0.2220;0.3600;0.4980;0.5040;0.8820;2.6640;4.4400;5.9100;6.7380;7.1460;7.2900]; % e.g values
dstrain = gradient(2*strain);
dstress = gradient(2*stress);
estress = stress.*(1+strain)
estrain = log(1+strain);
p=polyfit(log(dstrain),log(dstress),1);
m=abs(p(1));
b=(((abs(p(2)))));
yy=b.*(strain).^m;
plot(strain,stress,'LineWidth',1.5)
hold on
plot(strain,yy,'r--','LineWidth',2)
hold on
plot(estrain,estress,'-k','linewidth',1.5)
legend('engg stress-strain','exponetial curve fit','true stress-strain')
% axis([.001 .1 40 100])
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Stress and Strain에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!