Need help finding a point on a line.
19 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposte (1)
Jacob Ward
il 6 Set 2017
Modificato: Jacob Ward
il 6 Set 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 Commenti
David Goodmanson
il 6 Set 2017
Although it's easier to just use polyval directly
y = polyval(p,2617);
Vedere anche
Categorie
Scopri di più su Get Started with Curve Fitting Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!