Plotting f(x,y)= (x+y)/(y/100+x/50) Using MATLAB in Region -2x<y<=0

Click For Summary
SUMMARY

The discussion focuses on plotting the function f(x,y) = (x+y)/(y/100+x/50) using MATLAB within the specified region defined by the inequalities -2x < y <= 0 and x <= 0. The user initially attempted to create a surface plot using meshgrid but encountered issues with unwanted regions. A solution was provided that involves creating masks to selectively display the desired area of the graph, ensuring that singularities along the line y = -2x are excluded. The final code snippet demonstrates the effective use of logical indexing to achieve the correct visualization.

PREREQUISITES
  • Familiarity with MATLAB syntax and functions
  • Understanding of meshgrid for creating coordinate matrices
  • Knowledge of surface plotting with the surf function
  • Basic concepts of logical indexing and masking in MATLAB
NEXT STEPS
  • Explore advanced MATLAB plotting techniques for complex functions
  • Learn about logical indexing and masking in MATLAB
  • Investigate the use of contour plots for visualizing functions
  • Study the implications of singularities in mathematical functions and their graphical representations
USEFUL FOR

Mathematics students, data scientists, and engineers who are using MATLAB for function visualization and need to understand how to manipulate plots to focus on specific regions of interest.

shogun61
Messages
1
Reaction score
0
f(x,y)=\frac{(x+y)}{(y/100+x/50)}
how can i plot this function with MATLAB in the region restricted between y=-2x and x=0 lines?
i wanted to plot that the second region of the cartesian coordinate
x=-1:0.1:0;
y=-2*x+eps , eps is very small
[X,Y]=meshgrid(x,y);
z=(X+Y)./(X/100+Y/50);
surf(z)

but it is not what i want.is there another way to plot this?
 
Physics news on Phys.org
Why so hard? Just plot regular, then remove the region you don't want

Edit: What I mean is, you can create masks and use them to selectively crop out undesirable portions of your graph (e.g. the singularities that occur along the y=-2x line) Note that your viewport will still be rectangular

x = -2:0.1:2;
y = -2:0.1:2;
[X,Y] = meshgrid(x,y);
Mu = X < 0;
Ml = Y > -2*X;
surf(X,Y,double(z.*Mu.*Ml));

Hope this helps.
 
Last edited:

Similar threads

  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 8 ·
Replies
8
Views
861
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 11 ·
Replies
11
Views
2K
Replies
1
Views
6K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K