Surface plot for a 3D function

In summary, This individual was trying to plot a surface given by a function, but did not know the expression explicitly. They had data for which the function defined a 3D surface. They attempted to interpolate the data and created a 4D plot.
  • #1
Telemachus
835
30
Hi there. I wanted to plot a surface, given implicitly by a function ##f(x,y,z)=c##, with ##c## a constant. My ##f(x,y,z)## is obtained numerically, so I don't know the expression explicitly, I have the values of ##f(x_i,y_j,z_k)## for given integer numbers ##(i,j,k)##, ##i=1,2,3...## same for ##j## and ##k##. And the discrete variables are ##x_i=(i-1)\Delta x## and similarly for ##y_j,z_k##.

So, in principle I can obtain, numerically a set of data for which ##f(x_i,y_j,z_k)=c##, where the ##x_i,y_j,z_k## are stored, and I know c (I just choose the value I want). And now I know that for those values, the magnitude of ##f(x,y,z)=c##, so this defines a 3D surface. Now, how can I plot this? it should be clear at this point that f might not define explicitly a function, it might not be bijective, it is likely to be a closed surface, like a spherical surface in 3D.
 
Technology news on Phys.org
  • #2
can you use Matlab?
 
  • Like
Likes Telemachus
  • #3
Yes, I can. But after thinking of it a bit, I think I should just plot my set of points, right? the obtained ##(x_i,y_j,z_k)## are the ones that defines my surface. Right?
 
Last edited:
  • #4
Actually, you can do that, but I don't think it's a "professional" way. If you do it, the figure you obtained will be a lot of dots :biggrin:
How about interpolating and approximating that function, then use MATLAB to plot it? :wink:
 
  • Like
Likes Telemachus
  • #5
Yes, that's a good idea. Is there a way to do it in MATLAB automatically? a way in which it plots the points, and makes the surface smooth by interpolation?
 
  • #6
As I know, MATLAB can't do it automatically, we must code an interpolation program to interpolate and approximate that function :frown:
 
  • Like
Likes Telemachus
  • #7
Ok. So here I have a set of data which I want to plot. I have also attached a plot of the data:

?temp_hash=fe4d2b10be01ef0dbe351705d9a7e895.png


So, as there are not many points, I really have to use some interpolation to get a descent picture. However, I don't think that even after the interpolation I will be able to plot it as a surface, I haven't found how to do it, but maybe if I have more points after interpolation, I can make it look more descent.

I was thinking to take pairs of points: (x,y), (x,z), (y,z) and make an interpolation for each pair. After that I can collect the whole bunch of data intro a single file back again, and plot it just like that. The idea is to have interpolations over the three planes.
 

Attachments

  • sur1001.txt
    5.4 KB · Views: 424
  • surface.png
    surface.png
    5.1 KB · Views: 352
  • ?temp_hash=fe4d2b10be01ef0dbe351705d9a7e895.png
    ?temp_hash=fe4d2b10be01ef0dbe351705d9a7e895.png
    5.1 KB · Views: 350
  • #8
Very easy in Mathematica. Here's the code to collect points {x,y,sin(x y)} in range (-2,2) and then I superimpose the actual plot (red) against the interpolation (blue):
Code:
p1 = Plot3D[Sin[x y], {x, -2, 2}, {y, -2, 2}, PlotStyle -> Red];
mySinTable =
  Flatten[Table[{x, y, Sin[x y]}, {x, -2, 2, 0.1}, {y, -1, 1, 0.1}],
   1];
mySinInterpolation = Interpolation[mySinTable];
p2 = Plot3D[mySinInterpolation[x , y], {x, -2, 2}, {y, -2, 2},
   PlotStyle -> Blue];
Show[{p1, p2}]
interpolation of sin.png
 

Attachments

  • interpolation of sin.png
    interpolation of sin.png
    23.7 KB · Views: 454
  • Like
Likes Telemachus
  • #9
Can you do that with the data I have provided? I am wondering if the fact that this data isn't a function ##z=f(x,y)## (not bijective) generates any issue in mathematica. If possible the interpolation has to be done in many directions. If you, for example, only interpolate along the fixed z curves, it will look poorly along the z axis, and the same applies for the other planes.

Thanks!
 
  • #10
Telemachus said:
Can you do that with the data I have provided? I am wondering if the fact that this data isn't a function ##z=f(x,y)## (not bijective) generates any issue in mathematica. If possible the interpolation has to be done in many directions. If you, for example, only interpolate along the fixed z curves, it will look poorly along the z axis, and the same applies for the other planes.

Thanks!

Post the data as a table {{x1,y1,z1},...,{xn,yn,zn}} and I'll try to run it through the code above and see what happens.
 
  • Like
Likes Telemachus
  • #11
Is it okey like this?

0.44736842105263153 0.73684210526315785 0.28947368421052633
0.47368421052631576 0.73684210526315785 0.28947368421052633
0.50000000000000000 0.73684210526315785 0.28947368421052633
0.52631578947368418 0.73684210526315785 0.28947368421052633
0.55263157894736836 0.73684210526315785 0.28947368421052633
0.47368421052631576 0.76315789473684204 0.28947368421052633
0.50000000000000000 0.76315789473684204 0.28947368421052633
0.52631578947368418 0.76315789473684204 0.28947368421052633
0.44736842105263153 0.68421052631578938 0.31578947368421051
0.55263157894736836 0.68421052631578938 0.31578947368421051
0.39473684210526316 0.78947368421052633 0.31578947368421051
0.60526315789473684 0.78947368421052633 0.31578947368421051
0.44736842105263153 0.65789473684210520 0.34210526315789469
0.55263157894736836 0.65789473684210520 0.34210526315789469
0.34210526315789469 0.71052631578947367 0.34210526315789469
0.65789473684210520 0.71052631578947367 0.34210526315789469
0.34210526315789469 0.78947368421052633 0.34210526315789469
0.65789473684210520 0.78947368421052633 0.34210526315789469
0.39473684210526316 0.81578947368421051 0.34210526315789469
0.42105263157894735 0.81578947368421051 0.34210526315789469
0.44736842105263153 0.81578947368421051 0.34210526315789469
0.55263157894736836 0.81578947368421051 0.34210526315789469
0.57894736842105265 0.81578947368421051 0.34210526315789469
0.60526315789473684 0.81578947368421051 0.34210526315789469
0.47368421052631576 0.63157894736842102 0.36842105263157893
0.50000000000000000 0.63157894736842102 0.36842105263157893
0.52631578947368418 0.63157894736842102 0.36842105263157893
0.34210526315789469 0.68421052631578938 0.36842105263157893
0.65789473684210520 0.68421052631578938 0.36842105263157893
0.31578947368421051 0.71052631578947367 0.36842105263157893
0.68421052631578938 0.71052631578947367 0.36842105263157893
0.31578947368421051 0.78947368421052633 0.36842105263157893
0.68421052631578938 0.78947368421052633 0.36842105263157893
0.42105263157894735 0.63157894736842102 0.39473684210526316
0.57894736842105265 0.63157894736842102 0.39473684210526316
0.34210526315789469 0.81578947368421051 0.39473684210526316
0.65789473684210520 0.81578947368421051 0.39473684210526316
0.34210526315789469 0.65789473684210520 0.42105263157894735
0.65789473684210520 0.65789473684210520 0.42105263157894735
0.31578947368421051 0.68421052631578938 0.42105263157894735
0.68421052631578938 0.68421052631578938 0.42105263157894735
0.44736842105263153 0.84210526315789469 0.42105263157894735
0.47368421052631576 0.84210526315789469 0.42105263157894735
0.50000000000000000 0.84210526315789469 0.42105263157894735
0.52631578947368418 0.84210526315789469 0.42105263157894735
0.55263157894736836 0.84210526315789469 0.42105263157894735
0.36842105263157893 0.63157894736842102 0.44736842105263153
0.63157894736842102 0.63157894736842102 0.44736842105263153
0.28947368421052633 0.71052631578947367 0.44736842105263153
0.71052631578947367 0.71052631578947367 0.44736842105263153
0.42105263157894735 0.84210526315789469 0.44736842105263153
0.44736842105263153 0.84210526315789469 0.44736842105263153
0.47368421052631576 0.84210526315789469 0.44736842105263153
0.50000000000000000 0.84210526315789469 0.44736842105263153
0.52631578947368418 0.84210526315789469 0.44736842105263153
0.55263157894736836 0.84210526315789469 0.44736842105263153
0.57894736842105265 0.84210526315789469 0.44736842105263153
0.47368421052631576 0.60526315789473684 0.47368421052631576
0.50000000000000000 0.60526315789473684 0.47368421052631576
0.52631578947368418 0.60526315789473684 0.47368421052631576
0.36842105263157893 0.63157894736842102 0.47368421052631576
0.63157894736842102 0.63157894736842102 0.47368421052631576
0.28947368421052633 0.71052631578947367 0.47368421052631576
0.71052631578947367 0.71052631578947367 0.47368421052631576
0.42105263157894735 0.84210526315789469 0.47368421052631576
0.44736842105263153 0.84210526315789469 0.47368421052631576
0.55263157894736836 0.84210526315789469 0.47368421052631576
0.57894736842105265 0.84210526315789469 0.47368421052631576
0.47368421052631576 0.60526315789473684 0.50000000000000000
0.50000000000000000 0.60526315789473684 0.50000000000000000
0.52631578947368418 0.60526315789473684 0.50000000000000000
0.39473684210526316 0.84210526315789469 0.50000000000000000
0.42105263157894735 0.84210526315789469 0.50000000000000000
0.57894736842105265 0.84210526315789469 0.50000000000000000
0.60526315789473684 0.84210526315789469 0.50000000000000000
0.47368421052631576 0.60526315789473684 0.52631578947368418
0.50000000000000000 0.60526315789473684 0.52631578947368418
0.52631578947368418 0.60526315789473684 0.52631578947368418
0.36842105263157893 0.63157894736842102 0.52631578947368418
0.63157894736842102 0.63157894736842102 0.52631578947368418
0.28947368421052633 0.71052631578947367 0.52631578947368418
0.71052631578947367 0.71052631578947367 0.52631578947368418
0.42105263157894735 0.84210526315789469 0.52631578947368418
0.44736842105263153 0.84210526315789469 0.52631578947368418
0.55263157894736836 0.84210526315789469 0.52631578947368418
0.57894736842105265 0.84210526315789469 0.52631578947368418
0.36842105263157893 0.63157894736842102 0.55263157894736836
0.63157894736842102 0.63157894736842102 0.55263157894736836
0.28947368421052633 0.71052631578947367 0.55263157894736836
0.71052631578947367 0.71052631578947367 0.55263157894736836
0.42105263157894735 0.84210526315789469 0.55263157894736836
0.44736842105263153 0.84210526315789469 0.55263157894736836
0.47368421052631576 0.84210526315789469 0.55263157894736836
0.50000000000000000 0.84210526315789469 0.55263157894736836
0.52631578947368418 0.84210526315789469 0.55263157894736836
0.55263157894736836 0.84210526315789469 0.55263157894736836
0.57894736842105265 0.84210526315789469 0.55263157894736836
0.34210526315789469 0.65789473684210520 0.57894736842105265
0.65789473684210520 0.65789473684210520 0.57894736842105265
0.31578947368421051 0.68421052631578938 0.57894736842105265
0.68421052631578938 0.68421052631578938 0.57894736842105265
0.44736842105263153 0.84210526315789469 0.57894736842105265
0.47368421052631576 0.84210526315789469 0.57894736842105265
0.50000000000000000 0.84210526315789469 0.57894736842105265
0.52631578947368418 0.84210526315789469 0.57894736842105265
0.55263157894736836 0.84210526315789469 0.57894736842105265
0.42105263157894735 0.63157894736842102 0.60526315789473684
0.57894736842105265 0.63157894736842102 0.60526315789473684
0.34210526315789469 0.81578947368421051 0.60526315789473684
0.65789473684210520 0.81578947368421051 0.60526315789473684
0.47368421052631576 0.63157894736842102 0.63157894736842102
0.50000000000000000 0.63157894736842102 0.63157894736842102
0.52631578947368418 0.63157894736842102 0.63157894736842102
0.34210526315789469 0.68421052631578938 0.63157894736842102
0.65789473684210520 0.68421052631578938 0.63157894736842102
0.31578947368421051 0.71052631578947367 0.63157894736842102
0.68421052631578938 0.71052631578947367 0.63157894736842102
0.31578947368421051 0.78947368421052633 0.63157894736842102
0.68421052631578938 0.78947368421052633 0.63157894736842102
0.44736842105263153 0.65789473684210520 0.65789473684210520
0.55263157894736836 0.65789473684210520 0.65789473684210520
0.34210526315789469 0.71052631578947367 0.65789473684210520
0.65789473684210520 0.71052631578947367 0.65789473684210520
0.34210526315789469 0.78947368421052633 0.65789473684210520
0.65789473684210520 0.78947368421052633 0.65789473684210520
0.39473684210526316 0.81578947368421051 0.65789473684210520
0.42105263157894735 0.81578947368421051 0.65789473684210520
0.44736842105263153 0.81578947368421051 0.65789473684210520
0.55263157894736836 0.81578947368421051 0.65789473684210520
0.57894736842105265 0.81578947368421051 0.65789473684210520
0.60526315789473684 0.81578947368421051 0.65789473684210520
0.44736842105263153 0.68421052631578938 0.68421052631578938
0.55263157894736836 0.68421052631578938 0.68421052631578938
0.39473684210526316 0.78947368421052633 0.68421052631578938
0.60526315789473684 0.78947368421052633 0.68421052631578938
0.44736842105263153 0.73684210526315785 0.71052631578947367
0.47368421052631576 0.73684210526315785 0.71052631578947367
0.50000000000000000 0.73684210526315785 0.71052631578947367
0.52631578947368418 0.73684210526315785 0.71052631578947367
0.55263157894736836 0.73684210526315785 0.71052631578947367
0.47368421052631576 0.76315789473684204 0.71052631578947367
0.50000000000000000 0.76315789473684204 0.71052631578947367
0.52631578947368418 0.76315789473684204 0.71052631578947367
 
  • #12
That will do. Just paste into myNumList as a string and (basically spherical):

Code:
myList = ReadList[StringToStream[myNumList], Record];
myDataPoints =
  ReadList[StringToStream[#], Record, RecordSeparators -> " "] & /@
   myList;
data2 = ToExpression[#] & /@ myDataPoints;
ListPointPlot3D[data2, BoxRatios -> {1, 1, 1}]
ListSurfacePlot3D[data2, BoxRatios -> {1, 1, 1}]

gives:
plotforpf.png
 

Attachments

  • plotforpf.png
    plotforpf.png
    40.2 KB · Views: 790
  • Like
Likes Telemachus
  • #13
Thanks a lot! I think I should make some interpolation anyway to get it nicer, or maybe run it with a finer grid size (which is certainly too computationally expensive). But that's exactly what I wanted. Thank you!
 
  • #14
Is that really a 3D plot?
I mean you give the x,y,z values but at each point you have a value for f... That's a 4D plot (that can be visualized with a gradient colored 3D plot)
 
  • Like
Likes Telemachus
  • #15
Yes. The plot of f(x,y,z) is four dimensional, because if you want to plot it, you would have to plot f(x,y,z) for each value of (x,y,z) But now I am fixing the value of f(x,y,z), f(x,y,z)=constant. So I have one dimension less, and what I am plotting is the (x,y,z) for which f(x,y,z)=some constant.
 
  • #16
aheight said:
That will do. Just paste into myNumList as a string and (basically spherical):

Code:
myList = ReadList[StringToStream[myNumList], Record];
myDataPoints =
  ReadList[StringToStream[#], Record, RecordSeparators -> " "] & /@
   myList;
data2 = ToExpression[#] & /@ myDataPoints;
ListPointPlot3D[data2, BoxRatios -> {1, 1, 1}]
ListSurfacePlot3D[data2, BoxRatios -> {1, 1, 1}]

gives:
View attachment 224872

Hi. I was finally trying to use this. However, I did not know how to introduce the list of numbers.

Could you exemplify with a list of a few numbers?

I get an error when I try to load the number list. Does mathematica has an issue with spaces between numbers? and is there a way to make mathematica interpret, for example, somethingE-002 as something##\times 10^{-2}##? I think I have an issue with that too.

My list of numbers looks like this now:

" 0.47368421052631576 , 0.10526315789473684 , 7.8947368421052627E-002 "
" 0.50000000000000000 , 0.10526315789473684 , 7.8947368421052627E-002 "
" 0.52631578947368418 , 0.10526315789473684 , 7.894736842052627E-002 "

And so on. There are blank spaces between the commas, but the forum ignores them.

I've defined at the beginning: myNumList= (And the list of numbers here).Thanks!
 

1. What is a surface plot for a 3D function?

A surface plot for a 3D function is a graphical representation of a mathematical function that has three independent variables. It shows the relationship between these variables on a 3D surface, with the height or color of the surface indicating the value of the function at each point.

2. How is a surface plot for a 3D function created?

To create a surface plot for a 3D function, the function must first be defined with three independent variables. Then, a grid of points is created within a specified range for each variable. The function is evaluated at each point and the resulting values are plotted on a 3D graph to form the surface. Different visualization techniques can be used to enhance the plot, such as color mapping or contour lines.

3. What information can be gathered from a surface plot for a 3D function?

A surface plot for a 3D function can provide insight into the behavior and relationships between the three variables in the function. It can also help identify patterns, peaks, valleys, and other features of the function. Additionally, it can be used to compare and contrast different functions or different versions of the same function.

4. What are the advantages of using a surface plot for a 3D function?

A surface plot for a 3D function allows for a more intuitive and comprehensive understanding of a function compared to a traditional 2D graph. It can also reveal complex relationships and patterns that may not be apparent in a 2D representation. Additionally, it can be useful for visualizing functions with multiple variables and identifying optimal solutions.

5. Are there any limitations to using a surface plot for a 3D function?

One limitation of using a surface plot for a 3D function is that it can be difficult to interpret and may require some mathematical background. Additionally, the accuracy of the plot depends on the number and spacing of the points used to create the surface. It can also be challenging to represent functions with more than three independent variables on a 3D surface.

Similar threads

  • Programming and Computer Science
Replies
2
Views
1K
Replies
5
Views
376
  • Calculus and Beyond Homework Help
Replies
5
Views
943
  • Programming and Computer Science
Replies
3
Views
343
  • Programming and Computer Science
Replies
2
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
12
Views
1K
  • Programming and Computer Science
Replies
31
Views
2K
  • Advanced Physics Homework Help
Replies
4
Views
448
  • Programming and Computer Science
Replies
4
Views
602
Replies
3
Views
1K
Back
Top