Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to plot a function on a Log scale, but am not getting the correct looking output. Any ideas on what could be wrong. MWE is below:

 F1=500 10^3;
 F2=50 10^3;
 k1=(2\[Pi] F1)/\[Omega]c;
 k2=(2\[Pi] F2)/\[Omega]c;
 \[Omega]c=Sqrt[Power[2.0, (3)^-1]-1.];
 \[Omega]=2\[Pi] f;
 s=I \[Omega];
 sL = s/k1;
 sH = s/k2;

 LogPlot[20Log[10,TB],{f,10,2 10^3},PlotRange:>{-20,10}]

Seen LogLogPlot but not sure of the difference between the two.

share|improve this question
I guess you want the $x$-axis to be in a log scale. Use LogLinearPlot. Have you tried reading the documentation‌​? Also, the $y$ values don't lie in the PlotRange you've specified. – Rahul Dec 8 '12 at 3:03
@RahulNarain: Still provides no output. I can show equivalent Matlab code that implements this but not sure how the plots work the same for MM? – night owl Dec 8 '12 at 3:15
Can you attach the plot that Matlab produces? – Rahul Dec 8 '12 at 5:35
@RahulNarain: Sure, here it goes. – night owl Dec 8 '12 at 5:44
@night owl You really need to explain what you're trying to do. Even with the matlab code, I can only try to guess what is going on, since you don't include any comments or units. I'm assuming you're trying to plot a transfer function, but the frequencies "f and w" have wrong units. And it only makes your code more difficult to understand. If you could explain what you're doing, we might be able to help – cartonn Dec 8 '12 at 17:44

There are several issues with the code above. The main problem is that you have a list of points that you want to plot instead of a function (and hence need to use ListPlot rather than Plot). Here is a corrected version.

 F1 = 500 10^3;
 F2 = 50 10^3;
 wc = (2^(1/3) - 1)^(1/2);
 k1 = (2*Pi*F1)/wc;
 k2 = (2*Pi*F2)/wc;
 K = 6;
 Av = 10^(K/20);
 f = Range[6000, 4 10^6, 1000];
 w = 2*Pi*f;
 s = I w;
 sL = s/k1;
 sH = s/k2;
 TL = Abs[(1/(sL + 1))^3];
 TH = Abs[(sH/(sH + 1))^3];
 TB = Av TL TH;
 ListLogLinearPlot[Transpose[{w/(2000 Pi), 20 Log10[TB]}], 
  PlotRange -> {{10, 2000}, {-20, 10}}]

bills code

share|improve this answer
Have you actually tried compiling it? It shows nothing? If you did render an output, could you attach here so I could see if it looks correct? – night owl Dec 8 '12 at 3:37
It gives the same plot (more or less) as the Matlab code. But really, generally, you would do yourself a favor instead of translating from Matlab, to go back to the equation you are trying to plot and do it right. In most cases, it would be far simpler, clearer, and shorter. – bill s Dec 8 '12 at 15:30
@bills I added a picture to your answer to help the OP - also added GridLines -> Automatic, GridLinesStyle -> Directive[Thin, LightGray, Dashed] to help it look similar to their Matlab output... – cormullion Dec 9 '12 at 17:02
@nightowl @bills Watch out about that capital K. That is a variable used internally by Mathematica, which even the StackExchange syntax highlighter has noticed. Could run you into trouble at some point. – thecommexokid May 6 '15 at 4:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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