# Mathematica - 2D plot for function of 2 vars?

• Mathematica
• dcnicholls
In summary, to create a series of 2D plots of a function with two variables, f(a,b), versus a, for a range of values of b, a second function f1(b) can be defined with the same formula as f(a,b) and used in the Plot function. Alternatively, a table can be created using the Table function for easier automation.
dcnicholls
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

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

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.

Thanks, useful improvement.

:

Yes, there is a simple way to create a series of 2D plots for a function of two variables in Mathematica. You can use the Plot function and specify the variable you want to vary (in this case, a) as the first argument, and then use the Table function to generate a list of plots for different values of the second variable (b). For example:

Plot[Evaluate[Table[f[a, b], {b, {10, 20, 50, 100}}]], {a, 1, 10}]

This will create a plot of f(a,b) vs a for each value of b specified in the Table function. You can also add options such as PlotStyle to customize the appearance of the plots. I hope this helps!

## 1. How do I plot a 2D function in Mathematica?

To plot a 2D function in Mathematica, use the Plot function and specify the function and range of values for the variables. For example: Plot[f[x,y], {x, xmin, xmax}, {y, ymin, ymax}]

## 2. Can I customize the appearance of the 2D plot?

Yes, you can customize the appearance of the 2D plot by using options such as PlotStyle, AxesLabel, and PlotRange. You can also add labels, legends, and annotations to the plot using the PlotLegends and Epilog options.

## 3. How can I plot multiple functions on the same 2D plot?

To plot multiple functions on the same 2D plot, use the Show function and specify the individual plots as arguments. For example: Show[Plot[f[x], {x, xmin, xmax}], Plot[g[x], {x, xmin, xmax}]]

## 4. Is it possible to save the 2D plot as an image or PDF?

Yes, you can save the 2D plot as an image or PDF by using the Export function. Specify the desired file format and file name as arguments. For example: Export["myplot.png", Plot[f[x,y], {x, xmin, xmax}, {y, ymin, ymax}]]

## 5. How do I add a color gradient to the 2D plot?

To add a color gradient to the 2D plot, use the ColorFunction option and specify a gradient function. You can also use the ColorData function to choose from a variety of pre-defined color gradients. For example: Plot[f[x,y], {x, xmin, xmax}, {y, ymin, ymax}, ColorFunction -> "Rainbow"]

• MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
535
• MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
• MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
• MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
970
• MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
1K
• MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
• MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
• MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
• General Discussion
Replies
2
Views
532