-3
$\begingroup$

I am new to Mathematica, and I have had extreme difficulty with Plot. Often, my plots simply don't appear. Here is my current code:

Maximal code example

I tried to avoid the common problems: for instance, making the functions explicitly depend on x_, y_, and c_. But still, nothing shows up in on the plot.

I did a minimal test with just a single function and without the Manipulate, still without any luck: minimal code example Does anyone know what might be going on?

$\endgroup$
4
  • 4
    $\begingroup$ Please post the code to test. $\endgroup$
    – cvgmt
    Nov 24, 2020 at 22:02
  • 4
    $\begingroup$ In the definition of PayoffCC use SetDelayed := rather than Set =. $\endgroup$ Nov 24, 2020 at 23:03
  • 1
    $\begingroup$ Even if one were to type out the code in the image you have posted, it would be impossible to help you without the definitions of the expressions named within the expressions you have posted in image form. Please, type out your code & provide these definitions or a MWE such that it will be better to solve your problem & aid future users in solving their problems as well. Thanks! $\endgroup$ Nov 25, 2020 at 1:03
  • $\begingroup$ Your PayoffCC plot works for me. However, as @RohitNamjoshi said, I would use := in the function definition, to avoid problems with any previous definitions of x, b, or c. $\endgroup$
    – MelaGo
    Nov 25, 2020 at 1:51

2 Answers 2

1
$\begingroup$

The problem is you are using a capital "P" for your function name.

Please try payoff[x_,b_,c_] =-(c + 2 b (x - 1)) x;

Plot[payoff[x, 4, 2], {x, 0, 1}, Axes -> False, Frame -> True]

enter image description here

$\endgroup$
6
  • $\begingroup$ Why are capital function names not allowed? I've used them before without any difficulty. $\endgroup$ Nov 25, 2020 at 0:12
  • $\begingroup$ The built-in functions of Mathematica all start with a capital letter. Perhaps Mathematica has a lookup table of built-in functions, and Plot[ ] looks there when the function to be plotted starts with a capital letter. $\endgroup$
    – mjw
    Nov 25, 2020 at 0:14
  • 7
    $\begingroup$ This is only a problem if you use the same name as a built-in function, which PayoffCC is not. Still better avoided to be on the safe side, but not the actual problem here. $\endgroup$
    – Chris K
    Nov 25, 2020 at 0:20
  • 1
    $\begingroup$ Then why did PayoffCC[ ] not payoff? $\endgroup$
    – mjw
    Nov 25, 2020 at 1:33
  • 3
    $\begingroup$ @mjw Did you try it yourself though?! It works perfectly fine! $\endgroup$
    – MarcoB
    Nov 25, 2020 at 2:15
4
$\begingroup$

Something is wrong on your side. It may be lingering definitions, or something else elusive, but your code works with the definitions you provided.

I would only recommend NOT starting with $b=0$ and $c=0$, because that will correspond to an empty plot... (Note the explicitly non-zero starting values in the Manipulate below)

Pccxx[x_, b_, c_] = c (x - 1) + b (1 - 2 x + 2 x^2)
Pddxx[x_, b_, c_] = -(c + 2 b (x - 1)) x
Pdcxx[x_, b_, c_] = 0. + 0.5 b - 0.5 c

Manipulate[
  Plot[
    {Pccxx[x, b, c], Pddxx[x, b, c], Pdcxx[x, b, c]},
    {x, 0, 1}
  ],
  {{b, 3}, 0, 10},
  {{c, 5}, 0, 10}
]

plot with three colored curves as result of Manipulate

$\endgroup$

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