Adding constraints to function plots in 2-D and 3-D
4 次查看(过去 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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!