Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica - 2D plot for function of 2 vars?

  1. Mar 24, 2012 #1
    I have a function of two variables, f(a,b). I want to create a series of 2D plots (on the same plot) of f(a,b) vs a, for a=1 to 10, for a set of discrete values of b (e.g. b=10,20,50,100).

    Is there a simple way to do this? Plot3D works, but I cannot find how to do it in 2D.

    DN
     
  2. jcsd
  3. Mar 24, 2012 #2
    Solved: Define a second function f1(b) with the same formula as f(a,b), and use:

    Plot[{f1[10],f1[20],f[50],f[100]},{a,1,10}]

    Does the job.

    DN
     
  4. Mar 24, 2012 #3

    Hepth

    User Avatar
    Gold Member

    Also if you want to automoate it more you can make it a table:

    Plot[Table[f1,{i,1,100,5}],{a,1,10}]

    Makes a table of f1 as i goes from 1 to 100 by 5. Easier if you want a lot of them.
     
  5. Mar 24, 2012 #4
    Thanks, useful improvement.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook