Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.2K Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How to define piecewise functions of two variables for NMinimize?

Posted 3 years ago
2 Replies

Hey Henrik,

that does help, thank you! I'll have to look into interpolated functions in Mathematica sometime.

I actually got it to work by using Minimize instead of NMinimize and simplifying the definitions of beta and gamma by reusing alpha. I was actually interested in a slightly different problem (with another piecewise function on the RHS instead of just 1/3 and some conditions to remove the trivial w=x=y=z=1 solution), but that change didn't pose any problems.

Kind regards,

Jesco

Jesco,

I do not really know why your approach using Piecewise is not working. But you could try with interpolated functions instead:

alpha = Quiet@FunctionInterpolation[\[Alpha][w], {w0}, InterpolationOrder -> 0];
beta = FunctionInterpolation[\[Beta][w, x], {w, 0, 500}, {x, 0, 500}, InterpolationOrder -> 0];
gamma = FunctionInterpolation[\[Gamma][w, x, y], {w, 0, 500}, {x, 0, 500}, {y, 0, 500}, InterpolationOrder -> 0];

And then:

NMinimize[{w + x + y + z, 
  w + alpha[w] x + beta[w, x] y + gamma[w, x, y] z >= 1/3 && 
   w \[Element] PositiveIntegers && x \[Element] PositiveIntegers && 
   y \[Elet] PositiveIntegers && 
   z \[Element] PositiveIntegers}, {w, x, y, z}]

(*   Out:    {4.`,{w\[Rule]1,x\[Rule]1,y\[Rule]1,z\[Rule]1}}   *)

Given your definitions this result is not really surprising - well, at least it seems to be correct.

Does that help? Regards -- Henrik

POSTED BY: Henrik Schachner
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard