Adding constraints to function plots in 2-D and 3-D

조회 수: 7 (최근 30일)
Adekunle Rotimi Adekoya
Adekunle Rotimi Adekoya 2021년 8월 27일
답변: Wan Ji 2021년 8월 29일
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
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
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 )

카테고리

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