Plotting a radial function f(r), in a 3d isotropic way, with axes (x,y,z=f(x^2+y^2)).

13 Ansichten (letzte 30 Tage)
I have a function f(r), where r=sqrt(x^2+y^2). In my data r, is an array which takes values from [0,8], for example: f(r)=sin(r). I don't have data for an array of x or y seperately. The function is perfectly isotropic. How can I create a 3-dimensional plot, where the function f(x^2+y^2) is presented versus x and y in the correct range?
Further explanation:
The vector of the values of f(r) is given. It was calculated from some numerical simulation (I don't have its analytic form). I don't have the vectors for x and y. The function is isotropic, so one can imagine that I just draw the same curve f(r) in every direction. But the problem I encounter for example, is how to create the vector Theta, x and y, so that they will have the correct number of sites, like f(r), and that they will represent f(r) in the 3-dimensional plot.

Akzeptierte Antwort

Dimitris Kalogiros
Dimitris Kalogiros am 22 Aug. 2018
I reshaped my code.
Lets say that we have loaded values of r and f(r) from a file. Cause I haven't these files , I must create these values.
Then for every value of r , I rotate a vector of length r , in order to take values of x and y. This is a reason for the arbitrary creation of this angle, which varies from 0 to 2pi.
For any given value of r, we have f(r) from our file and a very dense set of possible pairs (x,y) which form a vecor with magnitude r. In that way we can claim that we have "transformed" our function from f(r) to f(x,y) .... in fact to f(sqrt(x^2+y^2))
clc; clear; close all;
%%input data ( predefined)
% values of r (they are predefined and stored to a file)
r=0:0.1:8;
% values of f(r) (they are predefined stored to a file)
f=sin(r);
%%creation of x and y and connect them with f() stored values
% Angle between 0 and 2*pi, with arbitrary small step
% (small step means better accuracy)
phi=0:0.1:2*pi-0.1;
% creation of x and y
x=[];
y=[];
f_xy=[];
for n=1:length(r)
xtemp=r(n)*cos(phi);
ytemp=r(n)*sin(phi);
x=[x xtemp];
y=[y ytemp];
f_xy=[f_xy f(n)*ones(1, length(xtemp))];
end
%%plot
plot3(x,y,f_xy); zoom on; grid on;
xlabel('x'); ylabel('y'); zlabel('f');
grid on; zoom on;
..if you run the script you will receive this:
  2 Kommentare
Erez
Erez am 22 Aug. 2018
Fantastic! That's what I was looking for! Thank you very much.
Erez
Erez am 22 Aug. 2018
Quick follow-up: How can I color this curve, so that the color scheme will indicate height, like in a topographical map for instance? Thanks!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Dimitris Kalogiros
Dimitris Kalogiros am 22 Aug. 2018
Dear Erez
Here you are my suggestion:
clc; clear; close all;
% values of r
r=0:0.1:8;
% create values of x and y
phi=0:0.1:2*pi-0.1;
x=[];
y=[];
for n=1:length(r)
xtemp=r(n)*cos(phi);
ytemp=r(n)*sin(phi);
x=[x xtemp];
y=[y ytemp];
end
%calculate values of f()
f=sin(sqrt(x.^2 + y.^2));
% plot
plot3(x,y,f); zoom on; grid on;
xlabel('x'); ylabel('y'); zlabel('z');
grid on; zoom on;
My code is not optimum from the point of view of speed , but showes clearly how to overcome your problem
  1 Kommentar
Erez
Erez am 22 Aug. 2018
Bearbeitet: Erez am 22 Aug. 2018
Dear Dimitris, thanks for you reply. However perhaps I did not explain my question correctly. In your code you have : "%calculate values of f() f=sin(sqrt(x.^2 + y.^2));". The point is, that for me, the vector of the values of f(r) is given. It was calculated from some numerical simulation (I don't have its analytic form either). What I don't have, is the vectors for x and y, nor do I have Theta. The function is isotropic, so you can imagine that I just draw the same curve f(r) in every direction. But the problem I encounter for example, is how to create the vector Theta, x and y, so that they will have the correct number of sites, like f(r), and that they will represent f(r) in the 3-dimensional plot. I hope my explanation made it more clear...

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by