Finding the inflection point of a sigmoid function

16 次查看(过去 30 天)
Hi, here's my function:
% define params
p1 = 0.0389;
p2 = 1.9158;
p3 = 162.4272;
p4 = 0.012;
% simulate the function
syms x
f = p1+(p2-p1)/(1+10^((p3-x)*p4));
fplot(f,[1 245])
Now, I would like to find the inflection point (I manually drew where I roughly expect it to be).
Here's what I was trying to do:
double(solve(f,'MaxDegree',3))
but I get this:
ans = 2.1394e+01 - 1.1370e+02i
Which means that there is no real inflection point... Where's my mistake?
Thanks in advance
Iddo

采纳的回答

Star Strider
Star Strider 2017-12-18
Try this:
p1 = 0.0389;
p2 = 1.9158;
p3 = 162.4272;
p4 = 0.012;
% simulate the function
syms x
f(x) = p1+(p2-p1)/(1+10^((p3-x)*p4));
inflpt = vpasolve(diff(f,2) == 0); % Calculate Inflection Point
figure(1)
fplot(f,[1 245])
hold on
plot(inflpt, f(inflpt), 'pr', 'MarkerSize',10, 'MarkerFaceColor','g')
hold off
  4 个评论
Iddo Weiner
Iddo Weiner 2017-12-18
Yes, setting the 2nd derivative to equal zero will give you the inflection point

请先登录,再进行评论。

更多回答(2 个)

Roger Stafford
Roger Stafford 2017-12-18
编辑:Roger Stafford 2017-12-18
The inflection point occurs at x = p3. You can show it by using the symbolic 'diff' to find the second derivative of f with respect to x and finding the x that makes it zero. That occurs when 10^((p3-x)*p4)) is equal to 1 which forces x to equal p3.
  1 个评论
Iddo Weiner
Iddo Weiner 2017-12-18
Hey Roger, thanks for your help.
I understand what you say and it's right for this case, but I would like to have a piece of code that automatically calculates the inflection point.. Looking at the official documentation it looked like this line of code is supposed to do the work:
double(solve(f,'MaxDegree',3))
But, it didn't work.. So do you see a different way to automatically generate the inflection point? Or maybe I'm not using solve() properly?
Thanks, Iddo

请先登录,再进行评论。


Lalitesh
Lalitesh 2023-1-30
编辑:Torsten 2023-1-30
Hi,
I hope you have solved your inflection point problem. Could you please suggest me how to find inflection point in the given below case ?
y = [4941.325135
5373.592952
5341.265151
5109.495841
5164.985178
4910.347906
5036.098753
5210.505118
4897.930074
5303.555152
5059.674066
5294.250906
5045.080549
5139.444791
5184.016273
4989.822273
4879.351675
5037.299623
5193.317198
5126.702477
5114.934361
5163.894699
5250.845909
5236.142352
5425.261686
5026.998422
5181.941373
5043.063249
5226.955717
5045.126978
5285.330253
5147.00929
5089.199187
5433.585096
5259.022363
5135.878393
5075.663506
5068.604444
5240.425345
5013.836134
5235.932975
5293.152198
5362.597535
5288.109111
5034.519472
5095.714828
5267.142594
5168.69091
5050.240489
4921.738751
];
x = [-0.013607785
0.765345224
1.10289259
1.029090207
-0.022931512
-0.017396819
-0.074107114
0.769494196
2.98E-06
0.920557852
0.738470623
-0.025517765
0.820330824
0.561636238
1.02437854
0.748933493
-0.024258105
0.172846729
-0.040833861
1.015883315
0.961682273
0.974008018
-2.782219696
1.02138985
0.556479342
0.411214807
1.056242842
-3.368250299
1.094017765
1.128149932
-0.040686495
-0.013525985
-0.028379761
0.979391037
0.662479735
1.127613475
0.488222296
-0.067298217
1.022925141
-0.119633187
1.04065864
0.286375511
1.195491684
0.957996374
1.103174243
1.049128867
1.080726806
0.99141825
1.198772497
0.864385088
];
fn = @(b,x) b(5).*(b(1) + b(2)./(1 + exp(-b(3).*(x-b(4))))).^(b(6)) % Sigmoid Function (Objective Function)
fn = function_handle with value:
@(b,x)b(5).*(b(1)+b(2)./(1+exp(-b(3).*(x-b(4))))).^(b(6))
SSECF = @(b) sum((y - fn(b,x)).^2); % Sum-Squared-Error Cost Function
B0 = [-0.1; -0.1; -5; 0.1; 0.8; 10]; % Initial Parameter Estimates
[B,SSE] = fminsearch(SSECF, B0) % Estimate Parameters (B), Return Sum-Squared Error (SSE)
B = 6×1
-1.1849 -0.8181 51.3923 0.4650 6.0624 10.1272
SSE = 2.8669e+08 + 1.8180e+08i
xp = linspace(min(x), max(x))
xp = 1×100
-3.3683 -3.3221 -3.2760 -3.2299 -3.1837 -3.1376 -3.0915 -3.0453 -2.9992 -2.9531 -2.9069 -2.8608 -2.8147 -2.7685 -2.7224 -2.6763 -2.6301 -2.5840 -2.5379 -2.4918 -2.4456 -2.3995 -2.3534 -2.3072 -2.2611 -2.2150 -2.1688 -2.1227 -2.0766 -2.0304
figure(1)
plot(xp, fn(B,xp), '-r')
Warning: Imaginary parts of complex X and/or Y arguments ignored.
hold on
plot(x,y,'o')
hold off
  5 个评论
Torsten
Torsten 2023-1-30
编辑:Torsten 2023-1-30
Hopefully with better data.
Otherwise you can see the question as answered: impossible.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by