Need help finding a point on a line.

32 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Polynomials 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by