Code for Plotting Sphere function

19 views (last 30 days)
Can anybody share the complete code for plotting sphere function
like this
in matlab

Accepted Answer

John BG
John BG on 5 Sep 2016
Atinesh, 4 steps
1. define the [x y] grid:
2. build all possible points, there are other ways but this is the most compact one
3. Calculate the function points
4. 3D plot with surf
if you find this answer useful would you please be so kind to mark my answer as Accepted Answer?
To any other reader, please if you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John BG
  1 Comment
Atinesh Singh
Atinesh Singh on 5 Sep 2016
Can you help me with Rastrigin function
I'm using this code (Step 3), But it is producing Sphere function
Z = (X.^2 - 10*cos(2*pi*X) + 10) + (Y.^2 - 10*cos(2*pi*Y) + 10);

Sign in to comment.

More Answers (0)


Find more on Graphics Performance in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by