Menu

#3916 if statement in function ignored while plotting

None
not-a-bug
nobody
plotting (138)
1
2024-05-07
2022-01-12
No

if statement ignored while plotting

1 Attachments

Related

Bugs: #3916

Discussion

  • Alfons Schmid

    Alfons Schmid - 2022-01-12

    Hi, if I use an if statement in a functions it's working properly with aa value.
    While plotting the if is ignored.
    Please try:
    f(x):=block(x,if x>0 then x:0,x);
    f(10)= 0. This is right.
    Plotting it, the if statement is ignored e.g. with wxplot2d(f(x),[x,-100,100]);.
    In the result you will see a straight line. Alfons

     
  • Barton Willis

    Barton Willis - 2022-01-12
    • status: open --> not-a-bug
     
  • Barton Willis

    Barton Willis - 2022-01-12

    This isn't a bug. Instead try plotting

    wxplot2d('f(x),[x,-100,100]);
    

    Why is the quote needed? Consider:

    (%i15)  f(x):=block(x,if x>0 then x:0,x)$
    
    (%i16)  f(x);
    (%o16)  x
    

    If you all have more questions, please ask on the Maxima discussion list.

     
    • Alfons Schmid

      Alfons Schmid - 2022-01-12

      Thanks a lot,

      Didn't really get the sense of the quote.

      If I use an if else statement it will also work without quote:

      f(x):=block(if x>0 then x:0 else x)$

      wxplot2d(f(x),[x,-100,100])

      Von: Barton Willis [mailto:willisbl@users.sourceforge.net]
      Gesendet: Mittwoch, 12. Januar 2022 17:40
      An: [maxima:bugs]
      Betreff: [maxima:bugs] #3916 if statement in function ignored while plotting

      This isn't a bug. Instead try plotting

      wxplot2d('f(x),[x,-100,100]);

      Why is the quote needed? Consider:

      (%i15) f(x):=block(x,if x>0 then x:0,x)$

      (%i16) f(x);
      (%o16) x

      If you all have more questions, please ask on the Maxima discussion list.


      [bugs:#3916] https://sourceforge.net/p/maxima/bugs/3916/ if statement in
      function ignored while plotting

      Status: not-a-bug
      Group: None
      Labels: wrong plot
      Created: Wed Jan 12, 2022 04:25 PM UTC by Alfons Schmid
      Last Updated: Wed Jan 12, 2022 04:38 PM UTC
      Owner: nobody
      Attachments:

      if statement ignored while plotting


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/maxima/bugs/3916/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

      Related

      Bugs: #3916

  • Jaime E. Villate

    To see the real command you are giving to Maxima, after simplification, try quoting the plot2d to see what is going to be done:

    (%i1) f(x):=block(x,if x>0 then x:0,x)$
    (%i2) 'plot2d(f(x),[x,-100,100]);
    (%o2)                     plot2d(x, [x, - 100, 100])
    (%i3) g(x) := if x>0 then 0 else x$
    (%i4) 'plot2d(g(x),[x,-100,100]);
    (%o4)           plot2d(if x > 0 then 0 else x, [x, - 100, 100])
    

    See the difference between %o2 and %o4? The issue is not with plot2d but with the way Maxima has been designed. I hope you understand that the difference between f and g is that f has 2 commands while g has only one. The result of a function is always the result of the last command.

     
  • Alfons Schmid

    Alfons Schmid - 2022-01-12

    thanks for support. I see it is quite different to Octave or to C where a function is a function whatever you implement. Hm, so I think it's a good idea to compare the plot results with another application in future.

     
  • Jaime E. Villate

    Actually, the way you defined f , it has 3 commands.

     
  • Jaime E. Villate

    A function is a function in Maxima too, whatever you implement! f is the function; f(x) is the result of applying the function on x. You should then use:

    f(x):=(if x>0 then x:0,x);
    plot2d(f,[x,-100,100]);
    

    (No need for "block" in this case). And once again, let's not use this bug tracking system to discuss about Maxima; it is better to use the Maxima list.

     
  • Jaime E. Villate

    No! "wxmaxima" is a project separate from Maxima. The discussion list where you should register if you want to talk about Maxima is the one described in the Mailing list section of our website:
    https://maxima.sourceforge.io/maximalist.html

     

    Last edit: Jaime E. Villate 2022-01-14
  • Robert Dodier

    Robert Dodier - 2024-05-07
    • labels: wrong plot --> plotting
     

Log in to post a comment.