[R] finding value for a parameter in an equation

Frede Aakmann Tøgersen frtog at vestas.com
Wed Apr 23 10:53:34 CEST 2014


Hi Andras

I suppose you want to find the real root of your equation if such exists for the particular settings of the parameters. For that you can use uniroot().

So define a function based on your equation like this:

f <- function(E, D1, D2, IC501, IC502, ECON, ALPHA, M1, M2){
    1 - D1/(IC501*((E/(ECON-E))^(1/M1)))+D2/(IC502*((E/(ECON-E))^(1/M2))) +
        (ALPHA*D1*D2)/(IC501*IC502*((E/(ECON-E))^(0.5/M1+0.5/M2)))
}

Now do some plotting to see how the functions behaves:

## Parameters
D1 <-c(0.2,0.6,0.8)
D2 <-c(114,190,304)
IC501 <-0.62             
IC502 <-137.8
ECON <-5.95
ALPHA <-0.00005
M1 <-0.84 
M2 <-0.96

# vector for E
E <- seq(1,15, len = 100)

## three curves for each set of values of D1 and D2
plot(E, f(E, D1[1], D2[1], IC501, IC502, ECON, ALPHA, M1, M2), type = "l", col = "red")
lines(E, f(E, D1[2], D2[2], IC501, IC502, ECON, ALPHA, M1, M2), type = "l", col = "green")
lines(E, f(E, D1[3], D2[3], IC501, IC502, ECON, ALPHA, M1, M2), type = "l", col = "blue")

f() is only defined on the open interval (0;6).

Attached figure shows that there is real roots for the 3 values of  D1 and D2 somewhere between 0 and 1.

And those can be found as

> uniroot(f, c(0.0001,1), D1=D1[1], D2=D2[2], IC501=IC501, IC502=IC502, ECON=ECON, ALPHA=ALPHA, M1=M1, M2=M2)
$root
[1] 0.0003440589

$f.root
[1] 21.33889

$iter
[1] 14

$init.it
[1] NA

$estim.prec
[1] 6.103516e-05

> uniroot(f, c(0.0001,1), D1=D1[2], D2=D2[2], IC501=IC501, IC502=IC502, ECON=ECON, ALPHA=ALPHA, M1=M1, M2=M2)
$root
[1] 0.3840484

$f.root
[1] -9.45929e-05

$iter
[1] 9

$init.it
[1] NA

$estim.prec
[1] 6.103516e-05

> uniroot(f, c(0.0001,1), D1=D1[3], D2=D2[3], IC501=IC501, IC502=IC502, ECON=ECON, ALPHA=ALPHA, M1=M1, M2=M2)
$root
[1] 0.1476688

$f.root
[1] -0.001927616

$iter
[1] 9

$init.it
[1] NA

$estim.prec
[1] 6.103516e-05

>


> uniroot(f, c(0.0001,1), D1=D1[2], D2=D2[2], IC501=IC501, IC502=IC502, ECON=ECON, ALPHA=ALPHA, M1=M1, M2=M2)
$root
[1] 0.3840484

$f.root
[1] -9.45929e-05

$iter
[1] 9

$init.it
[1] NA

$estim.prec
[1] 6.103516e-05

But




Yours sincerely / Med venlig hilsen


Frede Aakmann Tøgersen
Specialist, M.Sc., Ph.D.
Plant Performance & Modeling

Technology & Service Solutions
T +45 9730 5135
M +45 2547 6050
frtog at vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender. 


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Andras Farkas
> Sent: 22. april 2014 21:33
> To: r-help at r-project.org
> Subject: [R] finding value for a parameter in an equation
> 
> Dear All,
> 
> please provide some insights for the following:
> 
> we have:
> 
> D1 <-c(0.2,0.6,0.8)
> D2 <-c(114,190,304)
> IC501 <-0.62
> IC502 <-137.8
> ECON <-5.95
> ALPHA <-0.00005
> M1 <-0.84
> M2 <-0.96
> 
> and the equation:
> 
> 1 = D1/(IC501*((E/(ECON-E))^(1/M1)))+D2/(IC502*((E/(ECON-
> E))^(1/M2)))+(ALPHA*D1*D2)/(IC501*IC502*((E/(ECON-
> E))^(0.5/M1+0.5/M2)))
> 
> In this equation the value for parameter "E" is what I am trying to calculate
> (all other parameters are known) for each pairs of D1 and D2 (ie: input D1[1]
> and D2[1] and the rest of the parameters first then substitute D1[2] and
> D2[2], then substitute D1[3] and D2[3]). It seems as if the equation can not
> be re-arranged so that "E" could be directly calculated, so looking to see if
> you could help me perhaps with a thought on how this could be solved with
> R,
> 
> thanks as always,
> 
> Andras
> 	[[alternative HTML version deleted]]

-------------- next part --------------
A non-text attachment was scrubbed...
Name: plot_of_f.png
Type: image/png
Size: 5682 bytes
Desc: plot_of_f.png
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20140423/e60f98c5/attachment-0002.png>


More information about the R-help mailing list