Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gnuplot fit of a nested function

What is the proper way in gnuplot to fit a function f(x) having the next form?

f(x) = A*exp(x - B*f(x))

I tried to fit it as any other function using:

fit f(x) "data.txt" via A,B 

and the output is just a sentence saying: "stack overflow"

I don't even know how to look for this topic so any help would be much appreciate it.

How are this kind of functions called? Nested? Recursive? Implicit?

Thanks

like image 397
user3916321 Avatar asked Aug 06 '14 23:08

user3916321


1 Answers

This doen't only fail for fitting, also for plotting. You'll have to write down the explicit form of f(x), otherwise gnuplot will loop it until it reaches its recursion limit. One way to do it would be to use a different name:

f(x) = sin(x) # for example
g(x) = A*exp(x - B*f(x))

And now use g(x) to fit, rather than f(x). If you have never declared f(x), then gnuplot doesn't have an expression to work with. In any case, if you want to recursively define a function, you'll at least need to set a recursion limit. Maybe something like this:

f0(x) = x
f1(x) = A*exp(x - B*f0(x))
f2(x) = A*exp(x - B*f1(x))
f3(x) = A*exp(x - B*f2(x))
...

This can be automatically looped:

limit=10
f0(x) = x
do for [i=1:limit] {
j=i-1
eval "f".i."(x) = A*exp(x - B*f".j."(x))"
}

Using the expression above you set the recursion limit with the limit variable. In any case it shall remain a finite number.

like image 74
Miguel Avatar answered Sep 23 '22 00:09

Miguel