Re: Equation solving from VFP

2022-12-20 Thread Paul Newton
Thank you Johan but your proposal won't work as it is because (i) the 
variables Ca, Cb, Va, Ka, Kb and Kw have not been specified (trivial to 
fix), (ii) VbCalc has not been specified and I am not sure what you 
intend it to be and (iii) even if I specify a value for VbCalc the line 
WHILE needs to be DO WHiLE and when it is corrected to DO WHILE 
generates a Data Type Mismatch error.


Clear
Ca = 0.1
Cb = 0.1
Vb = 10
Va = 10
Ka = 10^-4.757
? Ka
Kb = 10^-0.2
? Kb
Kw = 1.0E-14

HLow = 0
HHigh=1
H=(HHigh + HLow) / 2

VbCalc = 10
DO WHILE Abs(VbCalc = Vb - Va*[(Ca/(1 + H/Ka) - H + Kw/H)/(Cb/(1 + Kw/ 
(H*Kb)) + H - Kw/H)]) > 0.0005

  IF VbCalc < Vb
    HLow=H
  ELSE
    HHigh=H
  ENDIF
  H=(HHigh + HLow) / 2
ENDDO

? H

Paul

On 20/12/2022 07:18, Johan Nel wrote:

You can do it with binaray intersect.

Vb = 10
HLow:= 0
HHigh=1
H=(HHigh + HLow) / 2

WHILE Abs(VbCalc = Vb - Va*[(Ca/(1 + H/Ka) - H + Kw/H)/(Cb/(1 + Kw⁄ 
(H*Kb)) + H - Kw/H)]) > 0.0005

  IF VbCalc < Vb
    HLow=H
  ELSE
    HHigh=H
  ENDIF
  H=(HHigh + HLow) / 2
ENDDO

HTH

Johan Nel
South Africa

On 2022/12/14 01:49, Paul Newton wrote:

I have the following equation

Vb = Va*[(Ca/(1 + H/Ka) - H + Kw/H)/(Cb/(1 + Kw⁄ (H*Kb)) + H - Kw/H)]

Va, Ca, Ka, Cb, Kb and Kw are known or can be provided for any given 
"run" of the calculation.  Typical values might be


Va = 10, Ca = 0.1, Ka = 1.8E-5, Cb = 0.1, Kb = 0.63, Kw = 1.0E-14

The aim is to calculate H for various values of Vb and this requires 
"solving" for H. Various software packages do this in pretty much the 
same way but the terminology varies: Matlab uses "fsolve", Mathcad 
uses "find", Maple uses "solve" and Excel uses "GoalSeek".


I would like to try to find a way of doing this from VFP. Perhaps 
there is already a .NET DLL that could be called from VFP? Perhaps 
with a wrapper to act as a sort of mediator? Failing that, would it 
be a major task to create something in .NET (perhaps using an 
existing package)?


I really don't know, just thinking aloud ...

Paul Newton



[excessive quoting removed by server]

___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: https://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: https://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: https://leafe.com/archives
This message: 
https://leafe.com/archives/byMID/21c4552c-ace9-3e8a-0571-a22e2e7c9...@gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Re: Equation solving from VFP

2022-12-19 Thread Johan Nel

You can do it with binaray intersect.

Vb = 10
HLow:= 0
HHigh=1
H=(HHigh + HLow) / 2

WHILE Abs(VbCalc = Vb - Va*[(Ca/(1 + H/Ka) - H + Kw/H)/(Cb/(1 + Kw⁄ 
(H*Kb)) + H - Kw/H)]) > 0.0005

  IF VbCalc < Vb
    HLow=H
  ELSE
    HHigh=H
  ENDIF
  H=(HHigh + HLow) / 2
ENDDO

HTH

Johan Nel
South Africa

On 2022/12/14 01:49, Paul Newton wrote:

I have the following equation

Vb = Va*[(Ca/(1 + H/Ka) - H + Kw/H)/(Cb/(1 + Kw⁄ (H*Kb)) + H - Kw/H)]

Va, Ca, Ka, Cb, Kb and Kw are known or can be provided for any given 
"run" of the calculation.  Typical values might be


Va = 10, Ca = 0.1, Ka = 1.8E-5, Cb = 0.1, Kb = 0.63, Kw = 1.0E-14

The aim is to calculate H for various values of Vb and this requires 
"solving" for H. Various software packages do this in pretty much the 
same way but the terminology varies: Matlab uses "fsolve", Mathcad 
uses "find", Maple uses "solve" and Excel uses "GoalSeek".


I would like to try to find a way of doing this from VFP.  Perhaps 
there is already a .NET DLL that could be called from VFP? Perhaps 
with a wrapper to act as a sort of mediator?  Failing that, would it 
be a major task to create something in .NET (perhaps using an existing 
package)?


I really don't know, just thinking aloud ...

Paul Newton



[excessive quoting removed by server]

___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: https://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: https://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: https://leafe.com/archives
This message: 
https://leafe.com/archives/byMID/c1922019-990e-4e98-02b5-fa26a5a45...@xsinet.co.za
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Re: Equation solving from VFP

2022-12-14 Thread Paul Newton

Thanks Alan

I could certainly do that and I already have a workbook set up but I 
would prefer a non-automation method if possible.


Paul

On 14/12/2022 09:10, Alan Bourke wrote:

Thinking aloud, if you could guarantee 32-bit Excel was available you could 
probably use Excel automation to do it, i.e.

Create a Workbook programmatically
Fill defined cells with your input values
Do a Goal Seek with result in a defined cell
Read that value back to VFP.

 Range("B4").GoalSeek Goal:=-900, ChangingCell:=Range("B3")




___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: https://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: https://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: https://leafe.com/archives
This message: 
https://leafe.com/archives/byMID/83537c76-703a-5beb-e5a8-da614a330...@gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


Re: Equation solving from VFP

2022-12-14 Thread Christof Wollenhaupt
> Thinking aloud, if you could guarantee 32-bit Excel was available you could 
> probably use Excel automation to do it, i.e.


Actually, for Office automation it doesn't matter whether it's 32-bit or 
64-bit, as long as it is installed on the machine. 32-bit is only relevant for 
DLLs or drivers.

-- 
Christof


___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: https://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: https://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: https://leafe.com/archives
This message: 
https://leafe.com/archives/byMID/31889d12-9d66-4bec-b478-e97e6e7e4...@wollenhaupt.org
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


Re: Equation solving from VFP

2022-12-14 Thread Alan Bourke
Thinking aloud, if you could guarantee 32-bit Excel was available you could 
probably use Excel automation to do it, i.e.

Create a Workbook programmatically
Fill defined cells with your input values
Do a Goal Seek with result in a defined cell
Read that value back to VFP.

Range("B4").GoalSeek Goal:=-900, ChangingCell:=Range("B3")


-- 
  Alan Bourke
  alanpbourke (at) fastmail (dot) fm

___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: https://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: https://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: https://leafe.com/archives
This message: 
https://leafe.com/archives/byMID/d46dc8ac-2a1f-4b83-852b-4fd327ef8...@app.fastmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


Equation solving from VFP

2022-12-13 Thread Paul Newton

I have the following equation

Vb = Va*[(Ca/(1 + H/Ka) - H + Kw/H)/(Cb/(1 + Kw⁄ (H*Kb)) + H - Kw/H)]

Va, Ca, Ka, Cb, Kb and Kw are known or can be provided for any given 
"run" of the calculation.  Typical values might be


Va = 10, Ca = 0.1, Ka = 1.8E-5, Cb = 0.1, Kb = 0.63, Kw = 1.0E-14

The aim is to calculate H for various values of Vb and this requires 
"solving" for H. Various software packages do this in pretty much the 
same way but the terminology varies: Matlab uses "fsolve", Mathcad uses 
"find", Maple uses "solve" and Excel uses "GoalSeek".


I would like to try to find a way of doing this from VFP.  Perhaps there 
is already a .NET DLL that could be called from VFP?  Perhaps with a 
wrapper to act as a sort of mediator?  Failing that, would it be a major 
task to create something in .NET (perhaps using an existing package)?


I really don't know, just thinking aloud ...

Paul Newton


___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: https://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: https://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: https://leafe.com/archives
This message: 
https://leafe.com/archives/byMID/9293d867-e260-f2a4-3a38-e96d33394...@gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.