[R] Recherche de fonction
Berend Hasselman
bhh at xs4all.nl
Thu Jul 11 09:32:27 CEST 2013
On 11-07-2013, at 09:04, Raphaëlle Carraud <raphaelle.carraud at oc-metalchem.com> wrote:
> Hello,
>
> Thank you for your reply, even though I wrote in French.
>
> In reality, the variables r1, r4, r5 are expressed as functions of A, B, C, D, E, I and H, which are the variables I wish to calculate with the program. Those are expressed as functions of their derivatives in 6 of the 8 equation at my disposal. The two other equations are equilibrium that must be respected, and I found a publication in which they are solving this type of problem. Unfortunately, they did not say how.
>
> Considering those two algebraic equation, I considered my problem to be an algebraic differential equation system, which is said, according to R deSolve package documentation, to be possibly solved by the function daspk or radau. But I can't seem to make it work.
>
> For the initial values, the only ones I know for sure are A, B, C, D, E, I, G and H. Their derivatives are only approximations. I used them because the R documentation seems to say it was necessary (in the exemple) and because the function told me it didn't know dA, which is the first differential variable.
>
1. You should keep replies on the list so that others can follow the discussion and offer advice. I am sending this reply to the list.
2. Let's see if my analysis of your problem is correct.
You have a system of differential equations with dA,dB,dC,dD,dE,dI,dG,dH (8 in stead of the 7 I mentioned previously. I missed dD).
You have two equilibrium equations with K2 and K3 which describe a relation between A,B,C and D which must always be true?
These differentials are expressed as a system of linear equations in terms of the state variables.
You can write this as
Matrix %*% column-vector(dA,dB,…) = vector depending on state variables
where the matrix is 6 x 8 and the d-vector is 8x1.
That is an underdetermined system.
You could take the differential of the two equilibrium equations to get additional relationships between dA,dB,dC, and dD.
That should give you a square system of linear equations that you could solve with R's solve() assuming it is not singular or ill-conditioned.
I feel that you should try very hard to find out how such a system is solved in the paper you mention.
Before using deSolve you should first get the function that computes the d? variables in terms of the state variables working correctly.
Berend
> I will look at the link you proposed and see if I can make it work.
>
> Raphaëlle Carraud
>
> -----Message d'origine-----
> De : Berend Hasselman [mailto:bhh at xs4all.nl]
> Envoyé : mercredi 10 juillet 2013 21:02
> À : Raphaëlle Carraud
> Cc : r-help at r-project.org
> Objet : Re: [R] Recherche de fonction
>
>
> On 10-07-2013, at 20:42, Berend Hasselman <bhh at xs4all.nl> wrote:
>
>>
>> On 10-07-2013, at 16:21, Raphaëlle Carraud <raphaelle.carraud at oc-metalchem.com> wrote:
>>
>>> Bonjour,
>>>
>>> Je souhaite résoudre le couple d'équation différentielles suivant :
>>>
>>> 0 = -dA + dB + 2*dC - 2*r1 - 2*r5
>>> 0 = dA + dD + r1 + r4
>>> 0 = K2 - C/B^2
>>> 0 = K3 - D/(A*B)
>>>
>>> 0 = r5 + 2*r4 - dE
>>> 0 = r5 -dI
>>> 0 = -r5 - r4 - dG
>>> 0 = -r1/2 - dH
>>>
>>> en ayant connaissance des valeurs initiales de dA, dB, dC, dE, dI, dG, dH, r1, r2, r4, r5, K2, K3, A, B, C et D.
>>>
>>
>> If all initial values are known then plugging the values in the system will give 0 or not 0. There is nothing to "solve".
>>
>>> J'ai essayé plusieurs fonctions mais comme je ne peux pas lui faire calculer une des dérivée de laquelle découlerait les autre, il n'arrive pas à me fournir la solution.
>>> Je n'ai pas vu d'exemple qui pourrai s'assimiler à celui-ci dans la documentation.
>>>
>>
>> You will have to redo your query in English. Questions in French won't receive many replies.
>> My French is rudimentary but I'll try.
>>
>> You have 8 equations and 17 variables.
>> So how do you propose to "solve" the system?
>>
>> Assuming that the d? variables are differentials and that you want to solve for those:
>> you have 7 of these and 8 equations. So how to solve?
>>
>> But the third and fourth equations have no d? variables, so the may even be inconsistent given the values of K2, K3, C, B, A, D.
>> So you have 6 equations for 7 d? variables. So how do you propose to solve for the d? variables?
>>
>> Finally your system seems to be linear in the d? variables. You would be able to use R's solve() if you can get your system to be a square system.
>>
>> If your system is not square and underdetermined then you can use a
>> Moore Penrose inverse to get a minimum norm solution (http://en.wikipedia.org/wiki/Moore-Penrose_pseudoinverse#Minimum-norm_solution_to_a_linear_system).
>> package MASS provides a function ginv().
>
>
> And to make matters simple: since your lefthand sides are 0 the minimum norm solution of your system is 0.
>
> Berend
>
More information about the R-help
mailing list