Best fit line on Semi log graph

59 ビュー (過去 30 日間)
Maiesha Nujhat
Maiesha Nujhat 2020 年 10 月 25 日
コメント済み: Maiesha Nujhat 2020 年 10 月 25 日
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

採用された回答

Alan Stevens
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
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).
Maiesha Nujhat
Maiesha Nujhat 2020 年 10 月 25 日
Thank you so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by