5

I'm trying to adapt the following piece to the part where PowerF is a function of amax.

Z = Max[Z /. Solve[FullSimplify[PowerF, Z ∈ Reals] == P0, Z]]

Now I have modified my code because I want to also make a plot that depends on the parameter amax.

However the following does not work:

Z[amax_] := Max[Z[amax] /. Solve[FullSimplify[PowerF[amax], Z ∈ Reals] == P0, Z]]

How to fix this?

1 Answer 1

5

You're doing a replacement to get the solution, not evaluating a function in the Z /. part, so it can really be any variable. You'll end up with a recursion with a definition like Z[x_]:= f[Z[x]...]. So try something like:

Z[amax_] := Max[z /. Solve[FullSimplify[PowerF[amax], z ∈ Reals] == P0, z]]

If you want the variable that you're solving for to look similar to your function variable, then use formal symbols. It would look something like this:

enter image description here

As always, the standard warning to not use capital letters as function names and variables applies here.

8
  • Thanks, I will try this, but I think there was a problem when z was already set (by running it once with different amax). Is there a way to reset the value of z before doing a computation?
    – Jonas T
    Commented Apr 6, 2012 at 21:07
  • @JonasTeuwen Formal symbols cannot be assigned a value and so they'll never have phantom values from previous calculations.
    – rm -rf
    Commented Apr 6, 2012 at 21:08
  • @RM Right, good point! Can you explain why I cannot use capital letters as function names?
    – Jonas T
    Commented Apr 6, 2012 at 21:16
  • 1
    @Jon mma functions (at least, those exposed to the user) always start with a capital letter and there are single letter symbols such as D, E, I, N, etc. Invariably people use these and get confused when they get an error. Most of these symbols have the Protected attribute, meaning you can't modify them easily, however, some such as K don't, which will let you freely modify it, and there are instances where this has caused issues (and hard to debug since there is no obvious error message). Of course, you could say — "I'll avoid just those", but it's good practice to stick to convention.
    – rm -rf
    Commented Apr 6, 2012 at 21:23
  • @JonasTeuwen Z=. or, even better, ClearAll[Z] will do. Commented Apr 7, 2012 at 6:42

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.