Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #53265

Maximizing

From "Robert L." <No_spamming@noWhere_7073.org>
Newsgroups comp.lang.forth
Subject Maximizing
Date 2016-12-10 21:36 +0000
Organization Aioe.org NNTP Server
Message-ID <o2hshf$1ach$1@gioia.aioe.org> (permalink)

Show all headers | View raw


> I'm looping over two variables to maximize a function, returning x and
> y that maximize f.  Any way to do it without the setf in the body?
> 
> ; Here's a function you can paste to the REPL.
> 
> (defun f (x y)
>   (- (+ (* 9 x) (* 4 y))
>      (* x x)
>      (* y y))

A parenthesis is missing.

> 
> ; And here's what I'm trying to do:
> 
> (let ((best-x -1)
>       (best-y -1)
>       (max nil))
>   (loop :for x :below 10 :do
>         (loop :for y :below 10 :do
>               (let ((n (f x
> y)))
>                 (if (or (null max) (> n
> max))
>                     (setf best-x
> x
>                           best-y
> y
>                           max n)))))
>   (values best-x best-y))

Ruby:

def f x,y; 9*x+4*y-x*x-y*y; end

a=(0..9).to_a
a.product(a).max_by{|x| f *x}
 ===>
[4, 2]

In Forth?


-- 
Today Dr. Duke quoted an article from Breitbart on an agreement between the EU
and internet companies like Facebook, YouTube, and Twitter to effectively
censor "hate speech," which of course is anything Jews hate to hear.
http://www.renseradioarchives.com/dduke/

Back to comp.lang.forth | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Maximizing "Robert L." <No_spamming@noWhere_7073.org> - 2016-12-10 21:36 +0000
  Re: Maximizing jean-pierre@buechi-schmitt.ch - 2016-12-10 14:21 -0800

csiph-web