3
$\begingroup$

I'm quite new to Mathematica language, I am trying to figure out where I am making mistakes in Plotting a specific function that depends to other variables:

I want to plot

   Manipulate[Plot[{Im[fxDBL[φW, Λg]], 
   Im[fyDBL[φW, Λg]]}, {φW, 19, 
   23}], {Λg, 1.800, 2.500}]

I am defining the function fxDBL as

solution = Solve[φrad == π/2 + 1/2 (-π + aa - bb) + bb, aa];

fun = TrigExpand[Λg*λ/nres == Sin[aa - φrad] + Sin[bb + φrad]] /. solution[[1]] // Simplify;

solution2 = bb /. Solve[fun, bb] /. C[1] -> 1;

fxDBL[φW_,Λg_]:= ArcSin[nres*Sin[φW*π/180 - solution2[[2]]]]*180/π /. φrad -> φW* π/180;

but nothing is displayed... even if.., if I copy the final numerical output and defining fxDBL as

fxDBL[φW_, Λg_] := (
  180 ArcSin[
    1.49` Sin[(π φW)/180 - 
       ArcCos[0.17852348993288591` Λg Csc[(π \
φW)/180]]]])/π;

Mathematica plots correctly the function I need.

what am I missing? is it something related to the output of Solve that is not used properly with solution2[[2]]? Thank you

$\endgroup$
  • $\begingroup$ In your code here, λ and nres are not defined, but I assume they are equal to 0.532 and 1.49? $\endgroup$ – Jason B. Feb 22 '16 at 10:15
  • $\begingroup$ How is fyDBL[φW, Λg] in Manipulate defined? The code doesn't work even if you delete it, but the definition is missing $\endgroup$ – mattiav27 Feb 22 '16 at 10:18
3
$\begingroup$

The problem is that when you make the substitution /. φrad -> φW* π/180, the term φrad doesn't appear in the expression to the left. You can solve this in two ways, either use Set instead of SetDelayed,

fxDBL[φW_, Λg_] = 
 ArcSin[
     nres*Sin[φW*π/180 - 
        solution2[[2]]]]*180/π /. φrad -> φW* π/180

or use Evaluate,

fxDBL[φW_, Λg_] := 
 Evaluate[ArcSin[
     nres*Sin[φW*π/180 - 
        solution2[[2]]]]*180/π /. φrad -> φW* π/180]

Now your Manipulate works fine (assuming you define fyDBL at some point as well)

enter image description here

Edit

If you want to export your Manipulate as a gif animation, the non-intuitive way to do it is to export first as a movie, import that movie and export as a gif.

ManToGif[man_, name_String, step_Integer: 1] := 
 Module[{moviename}, 
  moviename = 
   name <> If[$OperatingSystem === "MacOSX", ".mov", ".avi"];
  Export[name <> ".gif", 
   Import[Export[moviename, man], "ImageList"][[1 ;; -1 ;; step]]];
  DeleteFile[moviename];]

This was adapted from Vitaliy's post on the community

$\endgroup$
  • $\begingroup$ May I ask how you made the movie of the manipulate window? What do you use? $\endgroup$ – Moo Feb 22 '16 at 13:42
  • 2
    $\begingroup$ @Moo - that is one of my new favorite functions. I'm using the ManToGif function defined here $\endgroup$ – Jason B. Feb 22 '16 at 13:44
  • $\begingroup$ Any ideas (cut and pasted his example) and get StringJoin::string: String expected at position 2 in charge<>Which[OperatingSystem==MacOSX,.mov,OperatingSystem==Windows,.avi]. >> Export::chtype: First argument charge<>Which[OperatingSystem==MacOSX,.mov,OperatingSystem==Windows,.avi] is not a valid file specification. >> Import::chtype: First argument $Failed is not a valid file, directory, or URL specification. >> Symbol::argx: Symbol called with 0 arguments; 1 argument is expected. >> $\endgroup$ – Moo Feb 23 '16 at 1:54
  • 1
    $\begingroup$ @Moo - try the updated code I posted here instead $\endgroup$ – Jason B. Feb 23 '16 at 16:59

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.