Taking second derivative and solving it for when it equals 0

Here is the code that I have:
clear all; close all
m = xlsread('1 MgO.xlsx','Sheet1','B1:J18');
temp = m(:,6);
MgO = m(:,3);
plot(temp, MgO,'*')
xlabel('Temperature (K)'); ylabel('Shear Modulus (GPa)'); title('MgO')
hold on
% Line of best fit
p = polyfit(temp,MgO,3);
y = polyval(p,temp);
plot(temp,y,'-')
SSE=sum((MgO-y).^2); SST=sum((MgO-mean(MgO)).^2); Rsquared=1-SSE/SST;
text(100,100,sprintf('y = %.3x^3 + %.3fx^2 + %.3fx + %.3f, R^2 = %.3f',p(1),p(2),p(3),p(4), Rsquared))
I'm trying to figure out how to get the second derivative and find at what temperature it equals 0. temp is my xaxis and MgO is my yaxis. I tried using the diff command but it didn't really work. Could someone help please?

 採用された回答

Star Strider
Star Strider 2019 年 3 月 21 日

0 投票

I am not certain what you are doing. Taking the derivative of data will significantly amplify any noise that might be present, so in general, it is best to take the derivative of a smooth signal. Also, you are fitting a polynomial, so the second derivative of that (regardless of the method you use) is giong to be a linear () function.
If you want to take the derivative of filtered data (eliminating as much noise as possible first), use the gradient (link) function. Use it two times to get the second derivative.
If you want to take the derivative of your fitted function ‘p’, one option is to use the polyder (link) function, again twice. You can then easily solve for the x-intercept of the linear relation this produces.
Note that the second derivative is 0 at a Saddle point (link).

4 件のコメント

Christina Kersten
Christina Kersten 2019 年 3 月 21 日
So what I'm trying to do is take the second derivative of the equation of the line of best fit and find where that equals to zero. So would I do polyder(polyder(p))?
Star Strider
Star Strider 2019 年 3 月 21 日
Yes.
If you define it as:
d2p = polyder(polyder(p));
the x-intercept is:
xint = -d2p(1)/d2p(2);
Christina Kersten
Christina Kersten 2019 年 3 月 22 日
Sorry, could you explain how dividing the first and second element of d2p gives you where d2p = 0?
Star Strider
Star Strider 2019 年 3 月 22 日
It should be:
xint = -d2p(2)/d2p(1);
That was what I intended to write, and I thought that was what I wrote.
The derivation comes from:
y = d2p(1)*x + d2p(2)
0 = dp2(1)*xint + d2p(2)
with the x-intercept defined by the point where y=0.

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

その他の回答 (1 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

製品

リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by