필터 지우기
필터 지우기

How to use surf to plot sphere function in matlab

조회 수: 11 (최근 30일)
Atinesh Singh
Atinesh Singh 2016년 9월 6일
답변: KSSV 2016년 9월 6일
I'm trying to plot sphere function below, But I'm getting wrong result
Here is the code I'm using
x1 = [-10:1:10];
x2 = [-10:1:10];
y = zeros(1,21);
for i = 1:21
y(i) = sphere([x1(i) x2(i)]);
end
Y = meshgrid(y);
surf(x1,x2,Y);
colormap hsv;
`sphere.m`
function [y] = sphere(x)
d = length(x);
sum = 0;
for i = 1:d
sum = sum + x(i)^2;
end
y = sum;
end
  댓글 수: 2
Walter Roberson
Walter Roberson 2016년 9월 6일
You can replace that code for sphere with
sphere = @(x) sum(x.^2);
Walter Roberson
Walter Roberson 2016년 9월 6일
This question appears to duplicate http://www.mathworks.com/matlabcentral/answers/301883-code-for-plotting-sphere-function . Please explain the difference between the questions, other than the fact that you posted code here.

댓글을 달려면 로그인하십시오.

채택된 답변

KSSV
KSSV 2016년 9월 6일

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by