Need help finding a point on a line.

31 Ansichten (letzte 30 Tage)
Grant Piephoff
Grant Piephoff am 6 Sep. 2017
Bearbeitet: Jacob Ward am 6 Sep. 2017
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

Antworten (1)

Jacob Ward
Jacob Ward am 6 Sep. 2017
Bearbeitet: Jacob Ward am 6 Sep. 2017
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 Kommentare
David Goodmanson
David Goodmanson am 6 Sep. 2017
Although it's easier to just use polyval directly
y = polyval(p,2617);
Jacob Ward
Jacob Ward am 6 Sep. 2017
Right, don't know why I didn't see that.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Polynomials finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by