2014-05-17 2 views
0

안녕하세요 저는 플롯 할 함수 f : [0,1]^2 -> R^2가 있습니다. f (x, y) = ((x + 1)/y, - (x + 1)/y). 나는 2 * N 그리드 라인과 (M + 1) 그리드 포인트로 구성된 [0,1]^2에 등거리 그리드를 만들어야한다.그리드의 2D 함수 플로팅


하지만 2 차원 기능을 수행하는 방법을 모르겠습니다. 나는 1D의 기능을 수행 할 수 있습니다

% Generate equidistant grid on [0,1] and plot grid points 
    M=25;    %number of internal grid points 
    xgrid = linspace(0,1,M+1)'; 
    null = zeros(size(xgrid)); 
    plot(xgrid,null,'.','MarkerSize',15) 
    % Sample function at the grid points and plot samples 
    ysample = xgrid+1; 
    plot(xgrid,ysample,'r.','MarkerSize',15); 
    title('Sampling a function on the grid') 
    hold off 

사람이 어떻게 2 차원 함수 f 위해 그것을 말해 수 : [0,1] -> R^2?

답변

1

이와 비슷한 것을 얻으려고하십니까?

M = 25; 
x = linspace(0, 1, M); 
y = linspace(0, 1, M); 
[mesh_x, mesh_y] = meshgrid(x, y); 
v1 = (mesh_x + 1) ./ mesh_y; 
v2 = -(mesh_x + 1) ./ mesh_y; 

figure('Name', 'My Plot'); 
subplot(121); 
surf(x, y, v1); 
grid on;xlabel('x');ylabel('y');zlabel('v1'); 
subplot(122); 
surf(x, y, v2); 
grid on;xlabel('x');ylabel('y');zlabel('v2'); 
관련 문제