Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have trouble defining the following function in Mathematica

sp[M_, u_] := 1/Sum[u^k M!/(M - k)!, {k, 0, M}]

After defining it Mathematica displays an error. And in fact it prints a pair of values, but my application requires only one, i.e 2 argument function. As the result I need to plot this function in 3D with u changing from 0.01 to 1, and M changing 1 to 100. Any suggestions?

share|improve this question

closed as off-topic by Kuba, m_goldberg, Sjoerd C. de Vries, Pinguin Dirk, Artes Sep 13 '13 at 7:32

This question appears to be off-topic. The users who voted to close gave these specific reasons:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Kuba, Artes
  • "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – Sjoerd C. de Vries, Pinguin Dirk
If this question can be reworded to fit the rules in the help center, please edit the question.

2  
What error? It's possible you have some old definition of sp around, try ClearAll[sp] and see if it works. –  ssch Sep 12 '13 at 21:58

1 Answer 1

up vote 1 down vote accepted
sp[m_, u_] := 1/Sum[u^k*(m!/(m - k)!), {k, 0, m}]; 
c = Table[sp[m, u], {m, 1, 100, 1}, {u, 0.01, 1, 0.01}]; 
ListPlot3D[c,
 DataRange -> {{1, 100}, {0.1, 1}},
 PlotRange -> All,
 ImagePadding -> 50,
 PlotRange -> All,
 PlotRangePadding -> 0,
 Boxed -> False,
 AxesLabel -> {m, n, "sp"}]

Mathematica graphics

Here is a version with Plot3D

Plot3D[sp[m, u], {m, 1, 100}, {u, 0.01, 1},
 PlotRange -> All,
 ImagePadding -> 50,
 PlotRange -> All,
 PlotRangePadding -> 0,
 AxesLabel -> {m, n, "sp"}]

Mathematica graphics

I used ListPlot3D also since I assumed the OP wanted only to sample the function at those specific points (0.01 for u and 1 increments for m) and it was easier to control those using Table. But whatever works for the OP.

share|improve this answer
1  
You have a dislike for Plot3D? :) –  Pickett Sep 12 '13 at 22:02
1  
Like so: Plot3D[sp[M, u], {M, 1, 100}, {u, 0.01, 1}, ColorFunction -> "Rainbow"] –  Pickett Sep 12 '13 at 22:02
1  
@Anon add PlotRange->All :) –  Kuba Sep 12 '13 at 22:04
    
@Kuba That's it! Plot3D[sp[M, u], {M, 1, 100}, {u, 0.01, 1}, PlotRange -> All]. –  Pickett Sep 12 '13 at 22:09

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