Mathematica: Plot using abstract variables instead of set values

In summary, the conversation discusses a method for making plots in Mathematica using variables instead of specific values. The solution involves rescaling the x-axis and labeling the plot and axis accordingly. An example code is provided for reference.
  • #1
rynlee
45
0
Hi All,

Does anyone know of a way to make plots in mathematica in terms of variables?

For example, suppose you had a function sin(a*x), and you wanted to plot it but did not want to set a to a specific value, the purpose being to have the graph report multiples of a, not specific numbers.

Usually I just throw in reasonable dummy values for whatever function, but it would be nice to be able to show nice clean fractions on a plot.

Thanks for any ideas!
 
Physics news on Phys.org
  • #2
You just have to rescale the x-axis. So plot Sin[x], but label the plot sin(a x) and the x-axis in units of x/a.

Try
Code:
Plot[Sin[x], {x, -4, 4}, AxesLabel -> {x/a, y == Sin[a x]}, 
                         Ticks -> {{-Pi, -Pi/2, 0, Pi/2, Pi}, {-1, 0, 1}}]
See the attached image.
 

Attachments

  • Sin(a x).png
    Sin(a x).png
    3.1 KB · Views: 659

1. Can I plot a function using abstract variables instead of set numerical values in Mathematica?

Yes, Mathematica allows you to plot functions using abstract variables such as x and y instead of specific numerical values. This can be done by using the Plot function and specifying the variables in the function you want to plot.

2. How do I plot multiple functions using abstract variables in Mathematica?

To plot multiple functions using abstract variables, you can use the Plot function with a list of functions as the first argument. For example, Plot[{x^2, Sin[x]}, {x, 0, 5}] will plot the functions x^2 and Sin[x] in the range of 0 to 5.

3. Is it possible to change the appearance of the plot when using abstract variables in Mathematica?

Yes, you can change the appearance of the plot by specifying options in the Plot function. Some options you can use include PlotStyle to change the color or style of the plot, and AxesLabel to add labels to the axes.

4. How can I include a legend in a plot using abstract variables in Mathematica?

To include a legend in a plot with abstract variables, you can use the PlotLegends option in the Plot function. For example, Plot[{x^2, Sin[x]}, {x, 0, 5}, PlotLegends -> {"x^2", "Sin[x]"}] will add a legend with the labels "x^2" and "Sin[x]" for the respective functions.

5. Can I add grid lines to a plot using abstract variables in Mathematica?

Yes, you can add grid lines to a plot by using the GridLines option in the Plot function. This option takes a list of values or functions to determine where the grid lines should be placed. For example, Plot[x^2, {x, 0, 5}, GridLines -> {Range[0, 5], Automatic}] will add grid lines at every integer value on the x-axis.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Calculus and Beyond Homework Help
Replies
4
Views
1K
  • General Math
Replies
7
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
9K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
Back
Top