0
$\begingroup$

UPDATED PORTION OF QUESTION AT THE BOTTOM

First, let me apologize for two things: 1) I'm very new to Mathematica, so this question is certainly very stupid, 2) I looked for the solution to this both on this site, as well as in the tutorial and website help documents. I'm sure the answer is there somewhere, but I fear I don't know enough about the software to fully understand what I'm looking for.

What I'm trying to do is nest one function inside of another, but not by using the "Nest" command (note, I'm going into detail in each step in case there are any additional errors I'm making, but just not noticing):

The first function is a relatively simple probability calculation for the chance of getting $h$ heads in $f$ flips, so I have:

prob[h_, f_ ] := (f!/(h! (f - h)!))/(2^f)

Now, I'd like to transform that probability by a transformation function $fp$:

fp[prob_] := 2 prob - prob^2

However, this doesn't seem to be working. Additionally, I'd like to be able to evaluate the $fp$ function for given values of $h$ and $f$- if anyone has any insights they'd be much appreciated!!

Thank you guys so much for your time!!!

Note: This seems to work alright (thanks to @kglr for pointing that out haha), but is directly related to the following updated question:

UPDATED:

I was hoping the case above would be a bit more generalizable, but I'm still having difficulty in a related (though slightly different) example:

I have a function $u$ that I would like to perform a basic transformation of the form:

u[z_] := -E^(-z)

I'd then like to call on the function $u$ in a new function $ud$ such that it takes any given number of heads $h$, transforms that number $h$ by the function $u$, and then multiply the result by the transformed probability for that number of heads $fp$. What I have to accomplish this is:

ud[fp_, u_, h_, f_] := u[h]fp[h,f]

But this isn't returning the desired result. That said, I'm not 100% sure I properly know how to feed in specific numbers to the aforementioned function, so the problem could be at a very basic level haha.

Thanks again!!!!

EDIT 2:

At the (wise) suggestion of @jjc385 my overall code is:

Clear[prob, h, f, fp, u, z, ud]
prob[h_, f_] := (f!/(h! (f - h)!))/(2^f)
(*prob[2, 2] +++ Just a check for the probability function *)
fp[prob_] := 2 prob - prob^2
u[z_] := -E^(-z)
ud[fp_, u_, prob_, h_, f_] := u[h] fp[prob[h, f]]
ud[fp, u, prob, 1, 2]

Which I actually think is working. Is there anything that immediately jumps out as incorrect? Otherwise, I think my issues are pretty much resolved!

On that note, though, I'd love it if one of you guys would post their comments as an answer so I can give it the credit/reputation that's well deserved!! Just going through it in response to the comments (such as the proper syntax for nesting functions in @kglr's comment, and the recommendation of @jjc385 for what to try, was (I think) what was needed!!

Thanks again guys! (Should I just edit a [CLOSED] into the Qustion Title, or is there another method to properly close a question? Again, If someone would like, I'd be more than happy to choose a top answer to close it too!)

$\endgroup$
  • 1
    $\begingroup$ fp[prob[5, 10]] gives 28287/65536 as it should, no? $\endgroup$ – kglr Sep 8 '17 at 16:58
  • 1
    $\begingroup$ Did you know Binomial[] is built-in? $\endgroup$ – J. M. will be back soon Sep 8 '17 at 17:09
  • $\begingroup$ A bit of a guess, but these might be related to what you are trying to do: (28056), (87985) $\endgroup$ – Mr.Wizard Sep 8 '17 at 17:14
  • $\begingroup$ For your update could you give a couple examples of the output (manually computed) that you desire? I am having trouble following your intended transformation. $\endgroup$ – Mr.Wizard Sep 8 '17 at 17:24
  • $\begingroup$ @kglr haha I think you're totally right- which is a bit disheartening because I was hoping to use what I messed up here and figure out what's not working correctly in some other parts of my code. $\endgroup$ – AndrewC Sep 8 '17 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.