Mathematica: plot and evaluate function of 2 variables

in summary, the spherical harmonic function can be plotted using spherical plot 3d in mathematica, but it may be missing a small detail. if the modification doesn't work then it may be helpful to divide the problem into simpler tasks.
  • #1
hasidim
15
0
Hi all,

I am trying to evaluate and plot a function of two variable in mathematica.

Function:

Code:
R(t,\theta) = a(t) + b(t)*Y_n(\theta)

Where a(t) and b(t) are functions (that I have evaluated already), and Y is the spherical harmonic for a given n, and R is the radius.

In mathematica I am unsure how to evaluate and plot a function of two variables in spherical coordinates. I attempted to use "SphericalPlot3D" to plot R as a function of \theta and \phi, and "Manipulate" to add a slider to adjust the time but am having no luck.

Any help would be APPRECIATED!
 
Physics news on Phys.org
  • #2
Is this something like what you are trying to do?

a[t_] := 2t; b[t_] := t^2; m = 1;(* < --- Substitute your functions here *)
R[t_, n_, m_, theta_, phi_] := a[t] + b[t]*SphericalHarmonicY[n, m, theta, phi]
Manipulate[SphericalPlot3D[R[t, n, m, theta, phi], {theta, 0, 2Pi}, {phi, 0, Pi}], {t, 0, 1}, {n, 0, 4, 1}]

Can you perhaps adapt this for what you need?
 
  • #3
Bill Simpson said:
Is this something like what you are trying to do?

a[t_] := 2t; b[t_] := t^2; m = 1;(* < --- Substitute your functions here *)
R[t_, n_, m_, theta_, phi_] := a[t] + b[t]*SphericalHarmonicY[n, m, theta, phi]
Manipulate[SphericalPlot3D[R[t, n, m, theta, phi], {theta, 0, 2Pi}, {phi, 0, Pi}], {t, 0, 1}, {n, 0, 4, 1}]

Can you perhaps adapt this for what you need?

That is pretty similar to what I have tried... but, I'll try copying that and modifying it.

As usual, I suspect that I am missing just one small detail.
 
  • #4
If your modification doesn't work then divide the problem into simpler tasks.
Confirm that
SphericalPlot3D[SphericalHarmonicY[1, 2, theta, phi]], {theta, 0, 2Pi}, {phi, 0, Pi}]
plot matches http://mathworld.wolfram.com/SphericalHarmonic.html
and substitute a few other values for the 1 and 2.
Then try a simpler Manipulate example using a Real and Integer value from the Help and confirm that works. That might uncover some of your missing details.
 
  • #5


Hello,

Thank you for reaching out for assistance with plotting and evaluating a function of two variables in Mathematica. I am happy to provide some guidance and tips for achieving your goal.

Firstly, in order to plot a function of two variables, you will need to use a 3D plot function such as "Plot3D" or "SphericalPlot3D". These functions take in three arguments: the function itself, the ranges of the two variables, and any additional options for the plot. In your case, the function is R(t,\theta) and the two variables are t and \theta. The ranges for t and \theta can be specified using the "Range" option in the plot function.

Next, you will need to define your function R(t,\theta) in Mathematica. You can do this by using the "DefineFunction" command. For example, you can write:

R[t_, \theta_] := a[t] + b[t] * SphericalHarmonicY[n, \theta, \phi]

Note that the variables t and \theta are defined as arguments in the function, and the SphericalHarmonicY function is used to represent Y_n(\theta) in your original function.

Once you have defined your function, you can then use it in the plot function. For example, you could write:

SphericalPlot3D[R[t, \theta], {t, tmin, tmax}, {\theta, \theta_min, \theta_max}, PlotRange -> All]

where tmin, tmax, \theta_min, and \theta_max are the desired ranges for the variables t and \theta.

Additionally, if you want to add a slider to adjust the time (t) in your plot, you can use the "Manipulate" function. This function allows you to create interactive plots by varying the values of certain parameters. For example, you could write:

Manipulate[SphericalPlot3D[R[t, \theta], {t, tmin, tmax}, {\theta, \theta_min, \theta_max}, PlotRange -> All], {t, tmin, tmax}]

This will create a slider for the variable t, allowing you to adjust the time in your plot.

I hope this helps you with your plot and evaluation of a function of two variables in Mathematica. Please let me know if you have any further questions or need additional assistance. Best of luck with your work!
 

FAQ: Mathematica: plot and evaluate function of 2 variables

What is Mathematica?

Mathematica is a powerful software program used for mathematical and scientific calculations, data analysis, and visualization. It is widely used by scientists, engineers, and mathematicians for a variety of purposes.

How do I plot a function of 2 variables in Mathematica?

To plot a function of 2 variables, you can use the Plot3D function in Mathematica. Simply type in the function and specify the range of values for each variable. The resulting plot will show the function in a three-dimensional space.

Can I evaluate a function of 2 variables at a specific point in Mathematica?

Yes, you can use the Evaluate function in Mathematica to evaluate a function at a specific point. Simply type in the function and specify the values for each variable within the Evaluate function. The result will be the value of the function at that point.

How can I customize the appearance of a 2 variable plot in Mathematica?

There are many options for customizing the appearance of a 2 variable plot in Mathematica. You can change the color scheme, add labels and titles, adjust the viewing angle, and more. You can also use the Manipulate function to interactively adjust the plot parameters.

Can I save and export a 2 variable plot in Mathematica?

Yes, you can save and export a 2 variable plot in Mathematica for use in other documents or presentations. You can save the plot as an image file or a PDF, or copy and paste it into another program. You can also use the Export function to specify the format and resolution of the exported plot.

Similar threads

Replies
1
Views
1K
Replies
1
Views
733
Replies
5
Views
2K
Replies
1
Views
812
Replies
2
Views
694
Replies
2
Views
1K
Replies
3
Views
2K
Replies
2
Views
2K
Back
Top