[Mathematica] Baffling bug in LogLinearPlot[]

In summary, the programmer attempted to use a function that was not designed for graphics output, and found strange and unexpected behavior.
  • #1
guerom00
93
0
Hello everyone,

This drives me nuts… I want to plot a function using LogLinearPlot. Take a look at what's happening :

[PLAIN]http://img208.imageshack.us/img208/8346/picture4b.jpg

I printed the values of the variable passed to my function because I didn't understand what happened… Although omega must vary from 1*^-2 to 10, it evaluates to the Log of that ! (log[1*^-2] is -4.605…)

More interesting, I change other parameters in my function (I put kx=1, kz=0 instead of 3) and look what happens :

[PLAIN]http://img687.imageshack.us/img687/9155/picture5c.jpg

The very first instance of omega is still evaluated as Log[1*^-2] (sic) and after that, it's fine and omega is evaluated according to its specified range.

This is incomprehensible if you ask me…
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
Your code is indecipherable to me. Here's some ideas though: right off you're using advanced constructs like @@ and all. If my code isn't working, the first thing I do is break it down and make it simpler without any functional constructs. Also, the word "Integrand" is not a standard function in Mathematica but I suppose you could create a function with that name although user-defined functions should begin with lower case letters. Also the GoldGratingSiInPlate option does not seem to exist as a standard color options in Mathematica 7. So first just strip it down to the basic syntax as possible even if it's messy. For example, construct a function for your data outside of LogPlot and then just try and plot it with Plot to see if the function is constructed correctly. Then start encapsulating it with functional constructs and other options if you want.
 
Last edited:
  • #3
Ah, you misunderstood… :smile:
The whole Integrand[] and so on : I defined that. This is not built-in Mathemartica stuffs :smile:
Replace it with whatever function, that's not the point :smile:
 
  • #4
I think what jackmell is trying to say is that you should try to come up with the "simplest working example" of your problem, so that we can try to advise you how to avoid it. Try to come up with the absolute simplest example you can find which reproduces your issue.

Without knowing how you've defined all your functions, it's impossible for any of us to figure out where the problem is coming from.

Edit: He's also giving you some style advice. It will help the readability of your code (for others) if you refrain from capitalising user-defined variables.

Edit2: Breaking errors down into the simplest working example is a good practise to get into. Often you will find the problem yourself by doing that. At the very least, you make it easier for people to help you, and if there actually is a bug in Mathematica, it will make it easier for them to track it down.
 
Last edited:
  • #5
Ok Devin. You said it better than me. What I'd do is hard-code my function:

myf[x_]=some reasonable expression here

then run the log plot:

LogLinearPlot[myf[x],{x,a,b}]

and see if that works. Then start building it up and also begin encapsulating various features along with the short-cuts of functional programming constructs. But I would do these one at a time to see where along the design I start having problems.
 
  • #6
There you go

[PLAIN]http://img268.imageshack.us/img268/8893/screenshot20100520at210.jpg

Trivial example, odd behavior for the first two evaluation of the variable z.
 
Last edited by a moderator:
  • #7
I think you're using a function in a manner that it was not designed for: LogLinearPlot is a graphics function for plotting a real-valued function as a function of the log of the independent variable. Also, first rule of thumb in Mathematica is do not use upper-case letters for user-defined variables or functions. Finally, it's way better if you just cut-and paste "raw code" in here so we can in turn cut-and-paste it directly into Mathematica. To do that, select the cell, then chose Cell/Convert To/Raw Input form and then cut and paste it.

Even when I run the much simpler routine:

myfun[x_]:=Print["x= ",x];

Plot[myfun[x],{x,0,1}]

amazingly it doesn't just say NO but rather does the same thing LogLinearPlot does and prints out a bunch of numbers beginning with "x" which I think is the iteration of the values of x, and then proceeds to print out a blank graph.
 
  • #8
Actually looking at it there is NOTHING weird about it.

Table[Log[z], {z, 1/100., 10}]
{-4.60517,0.00995033,0.698135,1.10194,1.38879,1.61144,1.79342,1.94734,2.08069,2.19834}

So that's the correct "z" plot I guess. Its most likely how it does the internal calculation converting from "z" to Log[z] for the plot.

Basically what you're doing is letting it determine how many "z"'s its going to calculate between 1/100 and 10, and itll probably do it logarithmically. You can force it though:

Table[Log[z], {z, 1/100., 10, 1/100.}]
{-4.60517, -3.91202, -3.50656, -3.21888, -2.99573, -2.81341, -2.65926, -2.52573, -2.40795, -2.30...

It basically chose : {1/100, 1+1/100, 2+1/100, ..., 9+1/100, 10}
 
  • #9
You're missing the point…
Here is how LogLinearPlot is _supposed_ to work : if the range of the plot is from 0.01 to 10 like in my example, it will evaluate the function on a regular grid in Log[x] but irregular grid in x i.e. at values that are the result of Range[Log[1*^-2],Log[10],(Log[10]-Log[1*^-2])/(PlotPoints-1)]//Exp[#]&/@#&. This indeed strictly goes from 0.01 to 10 as it should. LogLinearPlot should _never_ evaluates the variable outside the specified range.
 
  • #10
They aren't I thought? Log of 1/100 is the x position of the plot. In your range expression the lower limit is the negative 4. Why is that wrong?
 
  • #11
Hepth said:
In your range expression the lower limit is the negative 4.

There is an Exp[] mapped onto the whole Range[]. The lower limit is 0.01 :smile:
 
  • #12
Which version of MMA are you using?
Under Version 5 your simple example

In[1]:= <<Graphics`Graphics`
In[2]:= MyFun=Function[{x,y,z},Print["x= ",x," y= ",y," z= ",z];1];
LogLinearPlot[MyFun[1,1,z],{z,1*^-2,10}]

From In[2]:= x= 1 y= 1 z= 0.0100004
From In[2]:= x= 1 y= 1 z= 0.0100004
From In[2]:= x= 1 y= 1 z= 0.415264
...
and other similarly constructed examples do not show your problem.
 

1. What is the "baffling bug" in LogLinearPlot[]?

The "baffling bug" in LogLinearPlot[] refers to a known issue in the Mathematica software where the logarithmic scale on the x-axis is not displayed correctly in certain situations.

2. How does this bug affect my plots?

This bug can cause the x-axis to display incorrect tick marks and labels, making it difficult to accurately interpret the data on the plot.

3. Is there a workaround for this bug?

Yes, there are a few workarounds that can be used to avoid this bug. One option is to manually adjust the tick marks and labels on the x-axis using the Ticks function. Another option is to use the ScalingFunctions option in LogLinearPlot[] to manually specify the logarithmic scaling.

4. Has this bug been reported to the developers?

Yes, this bug has been reported to the developers of Mathematica. However, it has not yet been fixed in the latest versions of the software.

5. Can I still use LogLinearPlot[] in my analysis despite this bug?

Yes, you can still use LogLinearPlot[] in your analysis, but you will need to be aware of the potential for this bug to affect your plots. It may be helpful to double-check the tick marks and labels on the x-axis to ensure they are displaying correctly.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
978
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
4K
  • Programming and Computer Science
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
8K
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
Back
Top