Mathematica problem with plotting

In summary, the conversation is about plotting functions with different parameters on the same graph using a matrix A. The speaker is having trouble plotting and is wondering what they are doing wrong. The code provided involves creating a matrix A and using it to plot a function. The expert suggests using commas between rows in the matrix and simplifying the process by using matrix multiplication.
  • #1
asynja
16
0
Hello,
I'm trying to plot some functions with different parameters on the same graph. For each one I have to calculate some parameters from a matrix A. I need to plot this for several matrices A, so I'd like to be able to just copy-paste the new elements in the matrix A, rather than writing them in any other form. But it doesn't want to plot it. What am I doing wrong? Here's the code:

psi[n_, x_] := Exp[-x^2/2] Sqrt[1/(2^n n!)] HermiteH[n, x]

A = {{0, 1.00000000, 0, 0, 0, 0, 0, 0, 0, 0}
{0, 0.96702400, 0, 0, 0, 0.03485079, 0, 0.00757913, 0, 0}
{0, 0, 0, 0.33830360, 0, 0, 0, 0.00747333, 0, 0.00884880}
{0, 0.91306615, 0, 0, 0, 0.12627611, 0, 0, 0, 0}
{0, 0.89336436, 0, 0, 0, 0.15727524, 0, 0, 0, 0.00220772}
{0, 0.87655652, 0, 0, 0, 0.18238453, 0, 0, 0, 0.00976638}}

Plot[Evaluate[
Table[(A[[n]][[1]]*psi[0, x] + A[[n]][[2]]*psi[1, x] +
A[[n]][[3]]*psi[2, x] + A[[n]][[4]]*psi[3, x] +
A[[n]][[5]]*psi[4, x]), {n, 6}] ], {x, -5, 5}]
 
Physics news on Phys.org
  • #2
You need commas between the lists that form the rows of the matrix A. Also, did you mean to have all those zeros in A? The odd-numbered columns are all 0s.

You can accomplish what I think you're trying to do a bit more simply if you use matrix multiplication. After removing the zero columns from A, I used this command to produce the attached plot.

Plot[A.Table[psi[m, x], {m, 0, 4}], {x, -5, 5}]
plot.png
 

What is Mathematica and how is it used?

Mathematica is a computational software program used for solving complex mathematical, engineering, and scientific problems. It can perform a wide range of tasks such as symbolic and numerical calculations, data analysis, and 2D/3D plotting.

Why am I having trouble plotting my data in Mathematica?

There could be several reasons for this issue. It is possible that your data is not in the correct format, or that there are missing values. Another possibility is that the plot settings are not adjusted properly. It is important to check your data and plot settings to resolve any issues.

How can I customize my plot in Mathematica?

Mathematica offers various customization options for plots, such as changing the plot style, adding labels and titles, adjusting the axes, and adding legends. These options can be found in the Plot menu or can be specified within the plot function itself.

What is the difference between a 2D and 3D plot in Mathematica?

A 2D plot displays data on a two-dimensional plane, while a 3D plot displays data on a three-dimensional space. 3D plots can be useful for visualizing data that has multiple variables or for creating more complex visualizations.

How can I save my plot as an image in Mathematica?

To save your plot as an image, you can use the Export function in Mathematica. This allows you to save your plot in various formats, such as PNG, JPEG, or PDF. You can also specify the desired resolution and size for your image.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
146
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
270
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
228
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
904
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Back
Top