Help Plotting Mathematica Functions f(x,y) & sin(exp(xy))

  • Mathematica
  • Thread starter billyd690
  • Start date
  • Tags
    Mathematica
In summary, the goal is to plot both the surface graph of the function and the tangent plane to the surface on one plot. There are two functions I believe I'm having issues with: f(x,y) = cos(x+y)exp(x^2 - y^2) @ point (0.5,-0.5) and f(x,y) = sin(exp(xy)) @ point (1,1) . My code for the two are as follows respectively: Clear[f,x,y,fx,fy,point1,point2] and T[x,y]:=f[point1,point2]+fx[point1,point2](x-
  • #1
billyd690
3
0
The goal is to plot both the surface graph of the function and the tangent plane to the surface on one plot. There are two functions I believe I'm having issues with:

f(x,y) = cos(x+y)exp(x^2 - y^2) @ point (0.5,-0.5)

&

f(x,y) = sin(exp(xy)) @ point (1,1)

My code for the two are as follows respectively:

Clear[f,x,y,fx,fy,point1,point2]
point1=0.5;
point2=-0.5;
f[x_,y_]=cos(x+y)exp((x^2) - (y^2));
fx[x_,y_]=D[f[x,y],x];
fy[x_,y_]=D[f[x,y],y];
T[x_,y_]:=f[point1,point2]+fx[point1,point2](x-point1)+fy[point1,point2](y-point2)
T[x,y]

Clear[G1,G2];
G1=Plot3D[f[x,y],{x,-2,10},{y,-4,4}]
G2=Plot3D[T[x,y],{x,-2,10},{y,-4,4}]
Show[G1,G2,ViewPoint -> {0,-2,0.3},AspectRatio -> 1,AxesLabel -> {"x","y","f(x,y)"}]

for the second:

Clear[f,x,y,fx,fy,point1,point2]
point1=1;
point2=1;
f[x_,y_]= sin(exp(xy));
fx[x_,y_]=D[f[x,y],x];
fy[x_,y_]=D[f[x,y],y];
T[x_,y_]:=f[point1,point2]+fx[point1,point2](x-point1)+fy[point1,point2](y-point2)
T[x,y]

Clear[G1,G2];
G1=Plot3D[f[x,y],{x,-2,10},{y,-4,4}]
G2=Plot3D[T[x,y],{x,-2,10},{y,-4,4}]
Show[G1,G2,ViewPoint -> {0,-2,0.3},AspectRatio -> 1,AxesLabel -> {"x","y","f(x,y)"}]

I believe the outputs I'm getting are wrong. For the cos one it just plots a flat plane at 0. For the second one there isn't any plot. I've changed around the intervals and viewpoints, but still nothing shows up. Just looking for a little insight into the issue. thanks!
 
Physics news on Phys.org
  • #2
Change all the following

sin(x) to Sin[x]
cos(x) to Cos[x]
exp(x) to Exp[x]
xy to x*y
f[x_,y_]= to f[x_,y_]:= except for f[x_,y_]=D[], those need =
but you need to carefully check use of = versu := to make certain your functions are behaving exactly as you need
and separate each of your "statements" with semicolons.

Look at the scale of your G1 and G2 plots, One of those seems to range over -5*10^15 to 5*10^15 while the other ranges over -5 to 15 and I suspect that is a problem.

That should get you started. When you have all those fixed post an update showing what you have.

Mathematica is FANATIC about correct use of [] versus () versus {} and correct capitalization and correct use of = versus := versus == and there is even an === and those are all completely different. Make any tiny mistake with anyone of those and you will get incorrect results or error messages you may not understand or even nothing at all.
 
Last edited:
  • #3
Thank you for that! I am new to using Mathematica and didn't realize it was so case sensitive and such. I knew it was something but I wasn't sure because I didn't receive any error messages. I've got it know and have actual graphs now.

Thanks again.
 

1. How do I plot a mathematical function in Mathematica?

To plot a function in Mathematica, you can use the Plot function. For example, to plot the function f(x) = x^2, you would type "Plot[x^2, {x, 0, 10}]" into the Mathematica notebook. This will create a plot of the function from x = 0 to x = 10.

2. Can I plot a function with multiple variables in Mathematica?

Yes, you can plot a function with multiple variables in Mathematica. You will need to use the Plot3D function instead of the Plot function. For example, to plot the function f(x,y) = x^2 + y^2, you would type "Plot3D[x^2 + y^2, {x, 0, 10}, {y, 0, 10}]" into the Mathematica notebook.

3. How can I plot a complicated mathematical function in Mathematica?

To plot a complicated function in Mathematica, you can use the ContourPlot or DensityPlot functions. These functions allow you to visualize functions with multiple variables and complex expressions. You can also adjust the plot range and other parameters to customize the appearance of the plot.

4. How can I plot the function sin(exp(xy)) in Mathematica?

To plot the function sin(exp(xy)) in Mathematica, you can use the Plot3D function. You will need to use the Exp and Sin functions, and specify the variables x and y within the function. The resulting plot will show the variation of the function in three dimensions.

5. Can I add labels and titles to my Mathematica plots?

Yes, you can add labels and titles to your Mathematica plots. You can use the PlotLabel and AxesLabel options within the Plot or Plot3D functions to add labels to the plot. You can also use the PlotLegends option to add a legend to the plot.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
10K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
Replies
32
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
Back
Top