フィルターのクリア

Need help finding a point on a line.

19 ビュー (過去 30 日間)
Grant Piephoff
Grant Piephoff 2017 年 9 月 6 日
編集済み: Jacob Ward 2017 年 9 月 6 日
The problem I am tackling gives me a set of table values in regards to melting temperature and bonding energy. We are meant to plot the points, plot a best fit line, and then figure out the bonding energy for molybdenum, which has a melting temperature of 2617 C. So basically I need the y value for (2617,y)
Here is my code, everything works up to plotting the line, I just do not know what to type to code for the y value.
clear all, clc
BE=[62 330 285 850];
MT=[-39 660 962 3414];
plot(MT,BE,'x');
p=polyfit(MT,BE,1);
f=polyval(p,MT);
hold on
plot(MT,f,'--r')
title('Bonding Energy versus Melting Temperature')
xlabel('Melting Temp (C)')
ylabel('Bonding Energy (kJ/mol)')
grid on

回答 (1 件)

Jacob Ward
Jacob Ward 2017 年 9 月 6 日
編集済み: Jacob Ward 2017 年 9 月 6 日
The polyfit() function you are using gives you the slope and y-intercept of your best fit line. In this case, your p = [0.2190,108.1602].
Thus the equation for your line is y = 0.219 * x + 108.1602, so to find your y value, just plug 2617 in for x.
In code this would look like this:
x = 2617;
y = p(1)*x+p(2);
Or as was suggested, you could use polyval() which will give you the value of a polynomial at a given x. Like this:
x = 2617;
y = polyval(p,x)
  2 件のコメント
David Goodmanson
David Goodmanson 2017 年 9 月 6 日
Although it's easier to just use polyval directly
y = polyval(p,2617);
Jacob Ward
Jacob Ward 2017 年 9 月 6 日
Right, don't know why I didn't see that.

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

カテゴリ

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