Plotting Quadratics and ODE Solutions in Mathematica - A Guide for Beginners

In summary, to plot several quadratics and two numerical solutions to ODE's on the same graph in Mathematica, you can use the "Plot[]" function and add the desired plots to a list. To label each curve, you can use the "PlotLegends" option. Alternatively, you can use the "Show[]" function to combine the plots and label them individually.
  • #1
member 428835
Hi PF!

I am trying to plot several quadratics along with two numerical solutions to some ODE's. The command I entered for the two ODE's is

Plot[{{Evaluate[y[x] /. t]}, {Evaluate[y[x] /. s]}}, {x, 0, 1.2},
PlotRange -> All]

where s and t have been previously defined.

The plot for the quadratics is

Plot[Table[-.35 (1 - x)^2 + (1 - a)/2 (1 - x), {a,
Range[-1/5, 0, .06]}] // Evaluate, {x, 0, 1.2},
PlotLegends -> mList]

Both these commands give me plots, but I'd like them all to be on the same graph. Can someone please help?

Thanks so much!
 
Physics news on Phys.org
  • #2
You can just add them to your list.
Code:
Plot[{{Evaluate[y[x] /. t]}, {Evaluate[y[x] /. s]},Table[-.35 (1 - x)^2 + (1 - a)/2 (1 - x), {a,Range[-1/5, 0, .06]}] // Evaluate}, {x, 0, 1.2},PlotRange-> All,PlotLegends -> mList]
Or, if you want the quadratics to remain different colours, you can use "Show[]"
Code:
a=Plot[{{Evaluate[y[x] /. t]}, {Evaluate[y[x] /. s]}}, {x, 0, 1.2},PlotRange -> All]
b = Plot[Table[-.35 (1 - x)^2 + (1 - a)/2 (1 - x), {a, Range[-1/5, 0, .06]}] // Evaluate, {x, 0, 1.2},PlotLegends -> mList]
Show[a,b]
 
  • Like
Likes member 428835
  • #3
Thanks a ton! That's really helpful!
 
  • Like
Likes e.bar.goum
  • #4
Hey e.bar.goum, how would I label each curve (sorry I'm new to mathematica). Each quadratic is labeled but the other two curves are not.
 

1. What is Mathematica and how is it used in plotting quadratics and ODE solutions?

Mathematica is a powerful computational software program used by scientists and mathematicians to perform complex calculations and visualize data. It can be used to plot quadratic equations and solve ordinary differential equations (ODEs) by inputting the equations and using built-in functions and commands.

2. How do I plot a quadratic equation in Mathematica?

To plot a quadratic equation in Mathematica, use the Plot function and input the equation in the form of y = ax^2 + bx + c. For example, to plot the equation y = x^2 + 2x + 1, the command would be Plot[x^2 + 2x + 1, {x, -5, 5}]. This will create a graph of the equation with x values ranging from -5 to 5.

3. Can I plot multiple quadratic equations on the same graph in Mathematica?

Yes, you can plot multiple quadratic equations on the same graph in Mathematica by using the Plot function with multiple equations separated by a comma. For example, the command Plot[{x^2, x^2 + 2x + 1}, {x, -5, 5}] will plot both y = x^2 and y = x^2 + 2x + 1 on the same graph.

4. How can I solve an ODE in Mathematica?

To solve an ODE in Mathematica, use the DSolve function and input the ODE in the form of y'[x] = f[x, y]. For example, to solve the equation y'[x] = 2x + y, the command would be DSolve[y'[x] == 2x + y, y[x], x]. This will give the general solution for y as a function of x.

5. Can I visualize the solution of an ODE in Mathematica?

Yes, you can visualize the solution of an ODE in Mathematica by using the Plot function with the solution from DSolve. For example, if the solution of the ODE is given as y[x] = x^2 + C, the command Plot[x^2 + C, {x, -5, 5}] will plot the solution on a graph with x values ranging from -5 to 5.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
266
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
227
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
Back
Top