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.

  • 1
    $\begingroup$ 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. $\endgroup$
    – user484
    Dec 8, 2012 at 3:03
  • $\begingroup$ @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? $\endgroup$
    – night owl
    Dec 8, 2012 at 3:15
  • $\begingroup$ Can you attach the plot that Matlab produces? $\endgroup$
    – user484
    Dec 8, 2012 at 5:35
  • $\begingroup$ @RahulNarain: Sure, here it goes. i.stack.imgur.com/xi2kP.png. $\endgroup$
    – night owl
    Dec 8, 2012 at 5:44
  • 1
    $\begingroup$ @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 $\endgroup$
    – cartonn
    Dec 8, 2012 at 17:44

1 Answer 1


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

  • $\begingroup$ 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? $\endgroup$
    – night owl
    Dec 8, 2012 at 3:37
  • 3
    $\begingroup$ 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. $\endgroup$
    – bill s
    Dec 8, 2012 at 15:30
  • 1
    $\begingroup$ @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... $\endgroup$
    – cormullion
    Dec 9, 2012 at 17:02
  • $\begingroup$ @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. $\endgroup$ May 6, 2015 at 4:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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