[R] Fit NLE - was: computer algebra in R

Konrad
Fri, 08 Dec 2023 07:21:16 -0000

Dear all,


first I would like to thank Leo for his help and advice. My sincere
apologies for the delayed response; regrettably, I overlooked the email.


In order to characterize the problem a bit better I want to give
additional information and clarify the point where I have problems.


First of all the equation system is defined as:

h0 = h + hd + hg,
d0 = d + hd,
ga0 = ga + hg,
kga = hg/(h*ga),
kd = hd/(h*d)


The aim is to fit a non-linear equation in the form: signal ~ I0 + IHD *
hd + ID * d.


The parameters which should be identified/optimized are: I0, ID, IHD and
kd. However, the only information known is kga (33600.0), h0
(0.0000208), d0 (0.000079) and the guest concentration (= ga0).

In Mathematica the equation system is repeatedly solved for hd and d.
First the system 0 = h + hd + hga, 33600. = d + hd, ga0 = ga + hga,
0.000079 = hga/(ga*h), 0.0000208 = hd/(d*h) is passed to the Eliminate
function which eliminates four variables. In the case for hd the
variables h, d, hga and ga are eliminated. The resulting system is:?
3.71035392*^12 + 2.635566*^8*hd - 3783.*hd^2 == ga0*(-1.72536*^8 +
5135.*hd). Afterwards this system is used by a numerical solver to get
the result of hd.

My problem is how to replicate the Eliminate function in R. Or is it
possible to solely solve the system numerically?


Thanks a lot in advance.

All the best,

Konrad


On 04.12.23 23:10, Leo Mada wrote:
> Fit NLE - was: [R] computer algebra in R
> Original post:
> https://stat.ethz.ch/pipermail/r-help/2023-November/478619.html
>
> Dear Kornad,
>
> I think I have started to understand what you try to achieve. The
> problem is to fit a NLE and compute the parameters of the NL-Eq. I
> have included the R Help-list back in the loop, as I am not an expert
> in optimization.
>
> Goal:
> y ~ I0 + ?IHD * hd + ID * d;
> where:
> y = given vector of measurements;
> x = given vector of values;
> I0, IHD, ID, kd = parameters to optimize;
> hd = satisfies a polynomial of order 3;
>
> As d = d0 - hd, the previous formula can be written:
> y ~ I0 + ID * d0 + ?(IHD - ID) * hd;
>
> f(x, hd, kd) = 0,
> where f = a polynomial of order 3 in hd and order 2 in kd;
> d0 (and other components of the polynomial) = given constants;
>
> 1) First Approach
> I would back-substitute hd into the polynomial:
> hd = (y - I0 - ID*d0) / (IHD - ID);
>
> f(x, hd, kd) becomes then f(x, y, kd, I0, ID, IHD) = 0;
> - f is order 3 in y;
>
> You could fit:
> (y^3) ~ f(x, y, kd, I0, ID, IHD) - y^3,
> where you subtract the y^3 term from the function f, and add the (y^3)
> values as a new columng to the data.frame:
> data.frame(y3 = y^3, y=y, x=x)
>
> If the values of y are versy small (abs(y) << 1), then it may be
wiser
> to fit:
> y ~ f(x, y^2, y^3, kd, I0, ID, IHD) - (y-term);
>
> But I am not an expert in these problems. Other R-users may be more
> helpful.
>
> 2.) Approach 2: Math
> I feel that the problem can be solved quasy-exactly as well. It is
> much harder with 4 parameters to optimize:
> - one needs to compute the 4 partial derivatives;
> - solve the resulting system of 4 polynomial equations;
>
> The system is polynomial; although it looks ugly and I am not inclined
> to do such calculations myself.
>
> I hope that you can get more useful answers from the R help-list.
>
> Sincerely,
>
> Leonard
	[[alternative HTML version deleted]]