Best fit line on Semi log graph
조회 수: 62 (최근 30일)
이전 댓글 표시
Hello, I'm new to matlab. i want to plot a graph where x axis is in log scale and y axis is linear. The graph beow though shows straight line but I know the equation is not correct because It didn't pass throgh the scatter points
here is the code. Please help me, how can these line pass through the points and also how can i get the equation?
data=[0.891 35784.525582
0.91 39142.72
0.815 17679.26
0.891 25582
0.8861 30168.052]
p1=data(:,2); %Re
q1=data(:,1); %Cd
scatter(p1,q1)
set(gca,'XScale','log');
pp = polyfit(log(p1), q1, 1)
qq=exp(polyval(pp,log(p1)))
hold on
plot(p1, qq)
hold off
댓글 수: 0
채택된 답변
Alan Stevens
2020년 10월 25일
Like so
data=[0.891 35784.525582
0.91 39142.72
0.815 17679.26
0.891 25582
0.8861 30168.052];
p1=data(:,2); %Re
q1=data(:,1); %Cd
logp1 = log10(p1);
pp = polyfit(logp1, q1, 1);
qq=polyval(pp,logp1);
plot(logp1, qq,'-*',logp1,q1,'o'),grid
xlabel('log10(p1)'),ylabel('q1')
legend('fit','data')
댓글 수: 3
Alan Stevens
2020년 10월 25일
The Matlab figures come from fitting Cd to lo10(Re).
The Excel figures come from fitting log10(Cd) to log10(Re).
If we modify the MATLAB program to the following
data=[0.891 35784.525582
0.91 39142.72
0.815 17679.26
0.891 25582
0.8861 30168.052];
p1=data(:,2); %Re
q1=data(:,1); %Cd
logp1 = log10(p1);
logq1 = log10(q1);
pp = polyfit(logp1, logq1, 1);
qq=polyval(pp,logp1);
plot(logp1, qq,'-*',logp1,logq1,'o'),grid
xlabel('log10(Re)'),ylabel('log(Cd)')
legend('fit','data')
we get
pp =
0.1244 -0.6110
We can manipulate this as follows
% pp = 0.1244 -0.6110
% m = pp(1); c = pp(2)
% log10(Cd) = m*log10(Re) + c
% log10(Cd) = log10(Re^m) + c
% Cd = (10^c)*Re^m
% 10^c = 0.2449
% Cd = 0.2449*Re^0.1244
So the result depends on the type of fit, Cd vs log10(Re) or log10(Cd) vs log10(Re).
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!