# Creating a Logarithmic Scale Plot

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.];
K=6.0;
Av=10^(K/20);
frequencies=Table[f,{f,-6000,4000000,1000}];
\[Omega]=2\[Pi] f;
s=I \[Omega];
sL = s/k1;
sH = s/k2;
TL=Abs[(1/(sL+1))^3];
TH=Abs[(sH/(sH+1))^3];

TB=(Av)(TL)(TH);
LogPlot[20Log[10,TB],{f,10,2 10^3},PlotRange:>{-20,10}]


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

• 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.
– user484
Dec 8, 2012 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? Dec 8, 2012 at 3:15
• Can you attach the plot that Matlab produces?
– user484
Dec 8, 2012 at 5:35
• @RahulNarain: Sure, here it goes. i.stack.imgur.com/xi2kP.png. Dec 8, 2012 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 Dec 8, 2012 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}}]


• 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? Dec 8, 2012 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. Dec 8, 2012 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... Dec 9, 2012 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. May 6, 2015 at 4:16