Adding constraints to function plots in 2-D and 3-D
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi,
I am new to Matlab.
I have the code snippet below.
Assume that I want to skip parts of the domain of f, i.e. (x,y), where x^2 + y^2 = c (c is any constant value in my code).
So, I want the mesh function to only plot functional values of the points in the domain of my function, which satisfify the above constraint.
How do I go about editing the code snippet below in order to incorporate the type of constraint defined above?
You timely assistance would be appreciated.
f = @ (x , y ) x .* sin( x .* y );
[X , Y ] = meshgrid (0:.1:5 , pi :.01* pi :2* pi );
Z = f (X , Y );
mesh (X ,Y , Z )
댓글 수: 1
Wan Ji
2021년 8월 27일
I feel a litlle bit confused of your question, which domain should be skipped?
x^2+y^2<c
or
x^2+y^2>c
답변 (1개)
Wan Ji
2021년 8월 29일
Hi,
I have translated the Cartesian to polar system so as to satisfy your requirement
f = @ (x , y ) x .* sin( x .* y );
minR = sqrt(0+pi^2);
maxR = sqrt(5^2+(2*pi)^2);
minTheta = atan2(pi,5);
maxTheta = atan2(2*pi,0);
r = linspace(minR, maxR, 101);
theta = linspace(minTheta, maxTheta, 101);
[R, T] = meshgrid(r, theta);
X = R.*cos(T);
Y = R.*sin(T);
% [X , Y ] = meshgrid (0:.1:5 , pi :.01* pi :2* pi );
Z = f (X , Y );
Z(~(X<=5 & X>=0 & Y<=2*pi & Y>=pi)) = NaN;
mesh (X ,Y , Z )
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/724159/image.jpeg)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Sources에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!