# Trying to create a Gain (Bode) plot

I am trying to get this code to work and I can't seem to figure out what's going on. I realize that "simple" syntax problems are frowned on here but to us noobs they are NOT simple. (and the explanations in the documentation are often worse than useless -- they might as well be in Etruscan). And this is starting to bug me, no pun intended.

I used a variation on code supplied by @m_goldberg for a similar problem. All I did was change some variable names and try to add the log of a function (or rather, that function's result) to the plot. But I get a blank plot. So here's the code:

Remove["Global*"];
With[{r = 1000, \[ScriptL] = 1, c1 = 0.000001},
zc[w_] := 1/(I*w*c1);
zl[w_] := I*w*\[ScriptL];
H[w_] := zl[w]/(zl[w] + zc[w] + r);
G[H_] := 20*Log[Abs[H]];
Row[{
LogLinearPlot[G[H], {w, 10, 2*10^3}, GridLines -> Automatic,
GridLinesStyle -> Directive[Orange, Dashed], AxesLabel -> "Gain",
LabelStyle -> Directive[Blue, Bold], ImageSize -> 250],
LogLinearPlot[Arg@H[w], {w, 10, 2*10^3}, GridLines -> Automatic,
GridLinesStyle -> Directive[Orange, Dashed], AxesLabel -> phase,
LabelStyle -> Directive[Blue, Bold], ImageSize -> 250]}]]


I am trying to tease out what's wrong here. The second plot looks fine. The first on is the one that doesn't seem to work, though I get gridlines.

Thanks for your help and patience.

• Please link to the code you used – Dr. belisarius Oct 27 '14 at 0:20
• I put the code i used in there, what do you mean? – Jesse Oct 27 '14 at 0:21
• Change LogLinearPlot[G[H],...] to LogLinearPlot[G[H[w]],...]. – kglr Oct 27 '14 at 0:23
• @kguler - THANKS. Bloody hell this was driving me crazy. As an aside, someone needs to write "Mathematica for Dummies" soon. :-) – Jesse Oct 27 '14 at 0:25
• For two reasons: First, you posted non-working code, and second to give attribution to the original author – Dr. belisarius Oct 27 '14 at 0:26

With[{ r = 1000, ll = 1, c1 = 0.000001,
opts = {GridLines -> Automatic, GridLinesStyle -> Directive[Orange, Dashed],
LabelStyle -> Directive[Blue, Bold], ImageSize -> 250}},
zc[w_] := 1/(I*w*c1);
zl[w_] := I*w*ll;
H[w_]  := zl[w]/(zl[w] + zc[w] + r);
G[w_]  := 20*Log[Abs[H[w]]];
Row[{
LogLinearPlot[G[w], {w, 10, 2*10^3},     opts, AxesLabel -> "Gain"],
LogLinearPlot[Arg@H[w], {w, 10, 2*10^3}, opts, AxesLabel -> "Phase"]}]]


• Are you using version 9? – Mr.Wizard Oct 27 '14 at 9:44
• @Mr.Wizard Yes, still there – Dr. belisarius Oct 27 '14 at 12:11

Alternative modifications of your code to make it work as expected (second plot omitted):

ClearAll[zl, H, G, r, w];
With[{r = 1000, \[ScriptL] = 1, c1 = 0.000001}, zc[w_] := 1/(I*w*c1);
zl[w_] := I*w*\[ScriptL];
H[w_] := zl[w]/(zl[w] + zc[w] + r);
G[H_] := 20*Log[Abs[H]];
LogLinearPlot[G[H[w]], {w, 10, 2*10^3}, GridLines -> Automatic,
GridLinesStyle -> Directive[Orange, Dashed], AxesLabel -> "Gain",
LabelStyle -> Directive[Blue, Bold], ImageSize -> 250]]


ClearAll[zl, H, G, r, w];
With[{r = 1000, \[ScriptL] = 1, c1 = 0.000001}, zc[w_] := 1/(I*w*c1);
zl[w_] := I*w*\[ScriptL];
H = zl[w]/(zl[w] + zc[w] + r);
G[H_] := 20*Log[Abs[H]];
LogLinearPlot[G[H], {w, 10, 2*10^3}, GridLines -> Automatic,
GridLinesStyle -> Directive[Orange, Dashed], AxesLabel -> "Gain",
LabelStyle -> Directive[Blue, Bold], ImageSize -> 250]]


ClearAll[zl, H, G, r, w];
With[{r = 1000, \[ScriptL] = 1, c1 = 0.000001}, zc[w_] := 1/(I*w*c1);
zl[w_] := I*w*\[ScriptL];
H[w_] := zl[w]/(zl[w] + zc[w] + r);
G[H_] := 20*Log[Abs[H[w]]];
LogLinearPlot[G[H], {w, 10, 2*10^3}, GridLines -> Automatic,
GridLinesStyle -> Directive[Orange, Dashed], AxesLabel -> "Gain",
LabelStyle -> Directive[Blue, Bold], ImageSize -> 250]]
`

• thanks this also helps. I am finding this whole process maddening sometimes. (Some of it is just me getting old I suspect. I haven't done programming since BASIC and Pascal were a thing). – Jesse Oct 27 '14 at 0:39
• Jesse, you are not alone ... and, thanks to sites like Mathematica.SE, such frustrations are a little easier to cope with than the good/old Pascal/Basic days:) – kglr Oct 27 '14 at 0:46
• Are you also using version 9? My grid lines don't look like that. – Mr.Wizard Oct 27 '14 at 9:47
• @Mr.Wizard, yes I am still on Version 9. – kglr Oct 27 '14 at 9:53