Adding constraints to function plots in 2-D and 3-D
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Wan Ji
le 27 Août 2021
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
Réponses (1)
Wan Ji
le 29 Août 2021
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 commentaires
Voir également
Catégories
En savoir plus sur Sources dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!