Extend a line of best fit

95 ビュー (過去 30 日間)
Brian Robinson
Brian Robinson 2020 年 5 月 29 日
回答済み: Brian Robinson 2020 年 5 月 29 日
I have the following code which gives a plot and a line of best fit.
ARI_Weibull = ones(n,1)./P_Weibull;% Average Return Interval 1/P
figure
semilogx((ARI_Weibull), Q, 'r');
p_1 = polyfit(log(ARI_Weibull),Q,1); % Linear best fit
f_1 = polyval(p_1,log(ARI_Weibull));
hold on
semilogx(ARI_Weibull,f_1,'--r')
Q_100yr = polyval(p_1, log(100)) % Q value for 1 in 100 year
xline(100) ;
I now want to extend the line of best fit which I calculated to show its intersection with x = 100, which should correspond to a y value of Q_100yr calculated above.
How do I go about extending this line.
Thanks in advance,
Brian

採用された回答

KSSV
KSSV 2020 年 5 月 29 日
You have used polyfit, so you have slope and y-intercept in your hand. For a given value of x, you can find respective y value using polyval.
y_100 = polyval(p_1,100);
If you want to extend to certain range of values [xmin,xmax], also you can do using polyval.
m = 100 ;
xi = linspace(xmin,xmax,m) ; % give your values for xmin, xmax
yi = polyval(p_1,xi);
  2 件のコメント
Brian Robinson
Brian Robinson 2020 年 5 月 29 日
Ok well I have y_100 already as Q_100yr
My original figure looks like this:
Now I have done as you say:
m = 100;
xi = linspace(1,1000,100);
yi = polyval(p_1,xi);
Now what is the command to plot this? Because I tried semilogx(xi,yi) and that isn't right.
KSSV
KSSV 2020 年 5 月 29 日
yi = polyval(p_1,log(xi));

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

その他の回答 (1 件)

Brian Robinson
Brian Robinson 2020 年 5 月 29 日
Ok thanks for that.

カテゴリ

Help Center および File ExchangeInterpolation of 2-D Selections in 3-D Grids についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by