A Mathematica code to plot two functions on the same screen

  • Context: Undergrad 
  • Thread starter Thread starter hagopbul
  • Start date Start date
  • Tags Tags
    Mathematica Plot
Click For Summary

Discussion Overview

The discussion revolves around how to plot two functions simultaneously in Mathematica, specifically addressing the syntax and methods for achieving this. Participants explore different approaches to visualize the functions on the same screen, including using built-in plotting functions and online alternatives.

Discussion Character

  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant seeks to recall the correct Mathematica code to plot a function defined as F(x) = f(qi)/f(bn) for varying indices i and n.
  • Another participant suggests multiple methods for plotting, including using GraphicsRow and GraphicsColumn for side-by-side or stacked plots, respectively.
  • A specific example is provided using the functions Sin[x] and Cos[x] to demonstrate how to plot both functions on the same graph with appropriate styling and labels.
  • One participant notes they do not have Mathematica to test the provided example, indicating uncertainty about its functionality.
  • Another participant mentions Wolfram Cloud as a free online alternative to Mathematica for those without access to the software.
  • A participant expresses gratitude for verification of their code snippet by another user.

Areas of Agreement / Disagreement

Participants generally agree on the methods to plot functions in Mathematica, but there is no consensus on the initial query regarding the specific formulation of F(x) as it relates to the indices. Some uncertainty remains about the effectiveness of the provided solutions due to lack of testing.

Contextual Notes

Limitations include the lack of testing of the proposed code snippets by some participants, which may affect confidence in their applicability. The original function definition and its implications for plotting remain somewhat unclear.

Who May Find This Useful

This discussion may be useful for Mathematica users looking to plot multiple functions, as well as those interested in online alternatives for function visualization.

hagopbul
Messages
397
Reaction score
45
TL;DR
Trying to remember a Mathematica code
Hello :

Trying to remember a Mathematica code (plot)
If I want to plot two function on the same screen in the following way
F(x) = f( qi)/f(bn) which i = (0,...,n), n =(0,...,m)
For every value of i we plot F(x) for all the valuse of n for example F(x) = f(q0)/f(b(n=0,...,m) ),...etc
When I use the plot function it looks like it is ploting the function this way
F(x) = f(q(i =0,...,n))/f(b(n=0,...,m))

Best Regards
H
 
Physics news on Phys.org
So there's a couple of ways I found from searching the question:

1) Use GraphicsRow to plot them in separate plots side by side
2) Use GraphicsColumn to plot them in separate plots stacked on top of one another
3) Use Plot as shown in the example below:

[CODE lang="python" title="Mathematica plot of sin and cos from 0 to 2pi"](* Define the functions *)
f1[x_] := Sin[x]
f2[x_] := Cos[x]

(* Plot both functions on the same graph *)
Plot[{f1[x], f2[x]}, {x, 0, 2 Pi},
PlotStyle -> {Red, Blue},
PlotLegends -> {"Sin[x]", "Cos[x]"},
AxesLabel -> {"x", "y"},
GridLines -> Automatic,
PlotLabel -> "Plot of Sin[x] and Cos[x]"][/CODE]

Note: I don't have Mathematica so I couldn't test this example. Your mileage may vary.
 
jedishrfu said:
Note: I don't have Mathematica so I couldn't test this example. Your mileage may vary.
Here's what @jedishrfu's Mathematica example code evaluates to:

1741576332766.png
 

Attachments

  • 1741574012798.png
    1741574012798.png
    19 KB · Views: 48
Last edited:
  • Like
Likes   Reactions: jedishrfu
Thanks
For not having mathematica there is wolfram cloud which is like online mathematica for free
 
  • Like
Likes   Reactions: jedishrfu
hagopbul said:
Thanks
For not having mathematica there is wolfram cloud which is like online mathematica for free
Thank you @hagopbul . It wouldn't have helped me because I didn't know they generated similar output.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
946
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
967
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K