Need help finding a point on a line.
조회 수: 31 (최근 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
댓글 수: 0
답변 (1개)
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
2017년 9월 6일
Although it's easier to just use polyval directly
y = polyval(p,2617);
참고 항목
카테고리
Help Center 및 File Exchange에서 Polynomials에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!