0
$\begingroup$

I have an experimental function that is dependent on x and y [f(x,y)=Sin(ax/by)]. I am trying to make a 3D plot of f using the manipulate function so that I can easily input measured values of parameter f and h; where a and b are determined by f and h. The problem I have is that three conditions related to a and b hold important information for this experiment and I want the condition tested (according to the input values of f and h) and the result (severe, mild or normal) printed as PlotLabel. I have tried several options but I have not succeeded thus far. 1. Whenever I use on If statement testing one of the condition, I dont get any result at all. 2. However, when I added the other two, the code actually tested the correct condition according to the values I have in the input field but instead of putting the results directly above the plot as intended, it gives it as a new output field.

I would be very glad and grateful for your kind suggestions and recommendations. Many thanks!

My code:

Manipulate[
With[{a = (f + h) /(f*h) , b = f/(f*h) }, 
Plot3D[(Sin[(a*x)/(b*y)]) , {x, 0, 1}, {y, 0, 1}, 
PlotLabel -> 
Row[{"a = ", a, " m", Spacer[8], "|", Spacer[9], "b = ", b, " m", 
  "|", Spacer[9], If[(a) > (4*b), Print[mild]], 
  If[(a) = (4*b), Print[normal]], 
  If[(a) < (4*b), Print[severe]]}]]], {{f, 1, "1st constant"}, 1, 
5, 1, Appearance -> "Labeled"}, {{h, 1, "2nd constant"}, 1, 5, 1, 
Appearance -> "Labeled"}, ControlPlacement -> Left]
$\endgroup$

closed as off-topic by Szabolcs, Chris K, Carl Lange, m_goldberg, LCarvalho May 13 at 11:19

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

  • "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." – Szabolcs, Chris K, Carl Lange, m_goldberg, LCarvalho
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    $\begingroup$ Drop the Print and note the difference between = and == (please see the documentation). $\endgroup$ – Szabolcs May 12 at 19:53
  • $\begingroup$ @Szabolcs, many thanks for the clarifications. $\endgroup$ – Dean May 13 at 0:22
1
$\begingroup$

As mentioned in the comments by @Szabolcs, removing Print and changing If[(a) = (4*b) to If[(a) == (4*b) fixes the issue you were seeing:

Manipulate[
 With[{a = (f + h)/(f*h), b = f/(f*h)}, 
  Plot3D[(Sin[(a*x)/(b*y)]), {x, 0, 1}, {y, 0, 1}, PlotLabel ->
    Row[{"a = ", a, " m", Spacer[8], "|", Spacer[9], "b = ", b, " m", 
      "|", Spacer[9], If[(a) > (4*b), mild], If[(a) == (4*b), normal],
       If[(a) < (4*b), severe]}]]], {{f, 1, "1st constant"}, 1, 5, 1, 
  Appearance -> "Labeled"}, {{h, 1, "2nd constant"}, 1, 5, 1, 
  Appearance -> "Labeled"}, ControlPlacement -> Left]
  1. Print does not do what you think it does. It's unnecessary for the simple string concatenation you were doing, and more useful (along with Echo) for things like trying to track the internal state of a long-running function.
  2. You made a simple mistake with = vs ==. = is used to set values, while == is used to check equality. You can find out the details by evaluating ?= and ?== in Input cells in your notebook.
$\endgroup$
  • $\begingroup$ exactly what I needed. Many thanks! $\endgroup$ – Dean May 13 at 0:32

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