1
$\begingroup$

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.

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

Mathematica graphics

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

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]]

enter image description here

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]]

enter image description here

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]]

enter image description here

$\endgroup$
  • $\begingroup$ 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). $\endgroup$ – Jesse Oct 27 '14 at 0:39
  • $\begingroup$ 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:) $\endgroup$ – kglr Oct 27 '14 at 0:46
  • $\begingroup$ Are you also using version 9? My grid lines don't look like that. $\endgroup$ – Mr.Wizard Oct 27 '14 at 9:47
  • $\begingroup$ @Mr.Wizard, yes I am still on Version 9. $\endgroup$ – kglr Oct 27 '14 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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