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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
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:
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,ifx>0thenx: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(ifx>0then0elsex,[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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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):=(ifx>0thenx: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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
This isn't a bug. Instead try plotting
Why is the quote needed? Consider:
If you all have more questions, please ask on the Maxima discussion list.
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:
https://sourceforge.net/p/maxima/bugs/3916/attachment/wxmaxima%20bug%20if%2 0statement%20ignored%20while%20plotting.wxmx (12.4 kB;
application/octet-stream)
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:
#3916To see the real command you are giving to Maxima, after simplification, try quoting the plot2d to see what is going to be done:
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.
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.
Actually, the way you defined f , it has 3 commands.
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:
(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.
https://sourceforge.net/p/wxmaxima/discussion/create_topic/
https://sourceforge.net/p/wxmaxima/discussion/create_topic/ I cannot create
a topic. "You do not have permission to post in any forums."
Is this the right forum?
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