I have two functions: One of which outputs a number and the other outputs a picture. What I would like to do is create a single function that would output both the number and the picture.

As a MWE take the following:

Tri = Triangle[{{0, 0}, {0, 1}, {1, 0}}]
PictureTest[x_, y_, z_] := 
RegionPlot[x >= z*y && {x, y} ∈ Tri, {x, 0, 1}, {y, 0, 1}]
MinTest[x_, y_, z_] := Minimize[{x, x >= y + z && {x, y} ∈ Tri}, {x, y}]

I would like to create a new function NewFunc[x_,y_] that gives as an output both PictureTest[x,y,z] and MinTest[x,y,z]. (Or even better if it added some words and gave PictureTest[x,y,z] and "the minimum is MinTest[x,y,z].")

(This might seem silly given the specific functions above. But I'm working with more complicated functions and z is in fact many variables. So, in practice, I'd like to input "z" once and get the answer to both PictureTest and MinText. I imagine the answer is in the Mathematica documentation, but I don't quite know what I am looking for. I'm not even sure if I'm using the correct tags.)


1 Answer 1


Maybe something like:

ClearAll[pictureTest, minTest, newFunc]
pictureTest[z_] := RegionPlot[x >= z*y && {x, y} ∈ Tri, {x, 0, 1}, {y, 0, 1}]

minTest[z_] := Minimize[{x, x >= y + z && {x, y} ∈ Tri}, {x, y}]

You can use Through to get a list of results from applying a list of functions to a given input:

newFunc[z_] := Through[{pictureTest, minTest}@z]


enter image description here

  • 2
    $\begingroup$ better? Through[Labeled[pictureTest, minTest]@z] $\endgroup$
    – Mr.Wizard
    Feb 15, 2020 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.