Finding min point of a second derivative function
2 次查看(过去 30 天)
显示 更早的评论
What I have done is:
f=@(x)2./sqrt(pi).*integral(@(t)exp(-t.^2),0,x);
fplot(f,[-5,5])
DELTA=0.01;
X=-5:DELTA:5;
Y=f(X);
DY_DX=diff(Y)./DETLA;
But it does not work, is there an easier way to the first/second derivative? (not symbolic)
0 个评论
回答(1 个)
Eduard Reitmann
2018-8-3
You were almost there. Hope this helps. The zero in the differential is a bit crude (just to keep the vectors the same length), but a small enough step size should give you are very accurate answer.
f = @(x) (2./sqrt(pi)).*integral(@(t) exp(-t.^2),0,x);
dx = 0.01;
x = (-5:dx:5)';
y = arrayfun(f,x);
dydx = [0;diff(y)./dx];
d2ydx2 = [0;diff(dydx)./dx];
[dy2d2x_min,minpos] = min(d2ydx2);
x_min = x(minpos)
figure;
plot(x,[y dydx d2ydx2],x_min,dy2d2x_min,'*')
legend('erf(x)','erf''(x)','erf''''(x)')
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!