best approximation for double numbers

조회 수: 5 (최근 30일)
Francesco Pio
Francesco Pio 2023년 7월 21일
댓글: Walter Roberson 2023년 7월 21일
I have the following function which has an asymptote for y = 1 :
syms f(x)
syms x
f(x) = 1 / (1 + exp(-((x + 8.4730) / 10 )));
So, so the function should have a value < 1 for all x.
Also using "format long", of course, from a certain value of x onwards, the result of the function is approximated to 1.
format long
double(f(400)) % ans = 1
Is there a way to get an approximation to the exact value for even larger x? Or should I settle for this approximation?

채택된 답변

VBBV
VBBV 2023년 7월 21일
format long
syms f(x)
syms x
f(x) = 1 / (1 + exp(-((x + 8.4730) / 10 )))
f(x) = 
vpa(f(400),100)
ans = 
0.9999999999999999981792806433707777978855866136633285567221016451791545277454316141363423975013892837
  댓글 수: 2
VBBV
VBBV 2023년 7월 21일
Try using vpa for large values of x
Walter Roberson
Walter Roberson 2023년 7월 21일
syms f(x)
syms x
f(x) = 1 / (1 + exp(-((x + 8.4730) / 10 )))
f(x) = 
f1 = simplify(expand(1-f))
f1(x) = 
double(f1(400))
ans = 1.8207e-18
fplot(f1,[500 600])
f1n = matlabFunction(f1)
f1n = function_handle with value:
@(x)1.0./(exp(x./1.0e+1+8.473e-1)+1.0)
fplot(f1n, [500 600])
f1 gives you an idea of how quickly the value approaches 1, by showing you how quickly the difference between 1 and f falls. f1n shows that a numeric approximation (instead of a symbolic) of 1-f is still not bad at all in this kind of range.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numbers and Precision에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by