# [R] Solve equality function with GA

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Sun Sep 25 16:45:37 CEST 2022

```... and so you need f(x) = abs(x^2 - 25),
though I have no idea if GA handles non-continuously differentiable
functions.

-- Bert

On Sun, Sep 25, 2022 at 1:44 AM Eric Berger <ericjberger using gmail.com> wrote:

> ?ga states that ga() searches for the maximum of the fitness function.
> The maximum of your fitness function is at x=0.
>
>
>
> On Sun, Sep 25, 2022 at 4:52 AM Bert Gunter <bgunter.4567 using gmail.com>
> wrote:
>
>> We aren't supposed to do homework on this list.
>>
>> Bert Gunter
>>
>> On Sat, Sep 24, 2022 at 5:29 PM Barry King via R-help <
>> r-help using r-project.org>
>> wrote:
>>
>> > -------------------
>> > library(GA)
>> >
>> > # Solve for x where x^2 = 25, not x^2 <= 25
>> >
>> > f <- function(x)
>> > {
>> >   x^2-25
>> > }
>> >
>> > fitness <- function(x) -f(x)
>> >
>> > GA <- GA <- ga(type = "real-valued", fitness = fitness, lower = 0,
>> upper =
>> > 10)
>> > summary(GA)
>> > -------------------------
>> > Thank you,
>> > Barry King
>> >
>> > --
>> >
>> >
>> >
>> >
>> >
>> >
>> > This message is for the intended recipient only and may contain
>> > confidential and privileged information. If you are not the intended
>> > recipient, please return this message to the sender and delete this
>> message
>> > and any attachments from your computer.
>> >
>> >         [[alternative HTML version deleted]]
>> >
>> > ______________________________________________
>> > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>> >
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help