0
$\begingroup$

I have a problem in which the temperature is given at different radius for spherical ball. The temperature does not vary in theta and phi direction. The 2D representation is shown below:

enter image description here

The radius ranges from [0-112.5]. The data is given as:

r={0, 5.625, 11.25, 16.875, 22.5, 28.125, 33.75, 39.375, 45, 50.625, 56.25, 61.875, 67.5,73.125 78.75, 84.375, 90, 95.625, 101.25, 106.875, 112.5}

T={91.67957977, 91.67957977, 91.67957977, 91.67960856, 91.67960527, 91.6795804, 91.6793762, 91.67778452, 91.66602638, 91.58867628, 91.21715009, 90.23638055, 88.7682609, 87.08880295, 85.33335735, 83.57849684, 81.89021437, 80.34527736, 79.01720822, 77.9780673, 77.29413776}

I am trying to plot the above 2D graph into 3D spherical plot with different colors for temperature without any axis, but showing the scale for temperature similar to the graph shown below:

enter image description here

Thank you.

$\endgroup$
2
  • 1
    $\begingroup$ Dimensions /@ {r, T} reveals {{20}, {21}} i.e.; a mismatch in sizes of the arrays. Please fix it. Also, can you include Mathematica code for the 2D representation? $\endgroup$
    – Syed
    May 26, 2022 at 7:24
  • $\begingroup$ Thank you for pointing out the error, i have made error while tying the array. Also the figure 1 given here was plotted in origin lab, i wanted a 3d representation of the figure which has been provided by mr. Daniel. $\endgroup$
    – Danish
    May 28, 2022 at 8:24

1 Answer 1

1
$\begingroup$

You could proceed as follows:

-Interpolate the data (delete the last element of T as Syed noted)

-Define a piecewise function that returns 0 for radius > data range

-Use DensityPlot3D with a region function

Here is the code:

fr = Interpolation[Transpose[{r, Most@T}]];
f1[x_, y_, z_] = 
  Piecewise[{{fr[Sqrt[x^2 + y^2 + z^2]], 
     Sqrt[x^2 + y^2 + z^2] < 113}, {0, True}}];

m = 113;
DensityPlot3D[f1[x, y, z], {x, -m, m}, {y, -m, m}, {z, -m, m}, 
 Axes -> False, RegionFunction -> Function[{x, y, z}, x < 0 || y > 0],
  ColorFunction -> Function[{z}, Hue[7 z]], OpacityFunction -> None]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you so much for providing the code.This is what I need. $\endgroup$
    – Danish
    May 28, 2022 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.