Implicit plot with multi variable assumptions (symbolic math)

Hello,
I have to plot the following problem in symbolic form:
x*y + constant > 0 if x + y - constant2 > 0
i have used fimplicit and assume for the other condition but two problems arise: assume only seems to read one variable while fimplicit doesn't seem to work with assumptions.
Can anybody give me any helpful suggestion?
thank you

댓글 수: 7

Please include your code.
From the line
x*y + constant > 0 if x + y - constant2 > 0
I cannot deduce what you want to plot.
sorry about that, i should have known better.
here it is:
syms x y;
assume(x+y >= 2)
fimplicit(x*y +1, [-25 25])
thank you for helping
So you want to plot the points (x,y) with x*y+1 = 0 and x+y >= 2 ?
It looks to me you are asking to plot the set of points that satisfy both inequalities. So the locus of points (x,y), such that both
x + y >= 2
AND
x*y -1 >= 0
You CANNOT use fimplicit to perform that task. However, we can use fimplicit to plot the curves where the inequality reduces to an equality.
syms x y
fimplicit(x+y == 2)
hold on
fimplicit(x*y - 1 == 0)
As you can see, the one curve is a straight line. And so it defines a half plane, the part of the plane that falls above and to the right of the blue line there.
As far as the red curve is concerned, the part you will care about falls above and to the right of the curve in the first quadrant, or below and to the left of the red curve, in the third quadrant, And if so, then the blue line is immaterial here.
If those constants were different, then the blue line could come into play, but not for the example you pose.
thanks to both of you for your answers.
yes, i am trying to plot x+y>=2 AND x*y-1>=0, that's exactly it, as this is a part of a bigger problem that i need to solve symbolically.
As you said, fimplicit doesn't seem to suit, are there any other ways or functions that i could use? i also looked into assumptions but i didn't get any results.
i tried to solve the problem numerically, assigning numerical arrays to x and y, problem is i could potentially miss some important features in certain points that could be involuntarily excluded from the arrays.
once again, thank you
Plot the functions with "=". The region >= is above the respective graphs, the region <= is below the respective graphs. The region & is where all the regions intersect.
If you plot the region with a resolution that is fine enough (see below), you won't miss details if the functions are as well-behaved as the two that you used.
xlim_lower = -10;
xlim_upper = 10;
ylim_lower = -10;
ylim_upper = 10;
x = linspace(xlim_lower,xlim_upper,1000);
y = linspace(ylim_lower,ylim_upper,1000);
[X,Y] = meshgrid(x,y);
idx = (X+Y>=2 & X.*Y-1>=0);
X=X(idx);
Y=Y(idx);
plot(X,Y,'o')

Hi @LUCA D'AMBROSIO,

To address your query regarding, “yes, i am trying to plot x+y>=2 AND x*y-1>=0, that's exactly it, as this is a part of a bigger problem that i need to solve symbolically.As you said, fimplicit doesn't seem to suit, are there any other ways or functions that i could use? i also looked into assumptions but i didn't get any results.i tried to solve the problem numerically, assigning numerical arrays to x and y, problem is i could potentially miss some important features in certain points that could be involuntarily excluded from the arrays.”

Please see my response to your comments below.

Given your concerns about missing important features when using numerical arrays, I recommend utilizing a combination of logical operations and the fill function to create a shaded region that represents the solution set. This approach will allow to visualize the feasible region defined by the inequalities without relying solely on fimplicit, which will be more suited for equalities. Here is the complete code snippet to illustrate it.

    % Define the range for x and y
    x = linspace(-5, 5, 400);
    y = linspace(-5, 5, 400);
   [X, Y] = meshgrid(x, y);
    % Define the inequalities
    inequality1 = X + Y >= 2;      % x + y >= 2
    inequality2 = X .* Y - 1 >= 0; % xy - 1 >= 0
    % Combine the inequalities
    feasibleRegion = inequality1 & inequality2;
    % Plotting
    figure;
    hold on;
    % Fill the feasible region
    fill([-5 5 5 -5], [-5 -5 5 5], 'w', 'EdgeColor', 'none'); % Background
    h = fill(X(feasibleRegion), Y(feasibleRegion), 'b', 'FaceAlpha', 0.5);
    set(h, 'EdgeColor', 'none');
    % Add contour lines for the boundaries of the inequalities
    contour(X, Y, double(inequality1), [1 1], 'LineColor', 'r', 'LineWidth', 1.5);
    contour(X, Y, double(inequality2), [1 1], 'LineColor', 'g', 'LineWidth', 1.5);
    % Set axis limits and labels
    xlim([-5 5]);
    ylim([-5 5]);
    xlabel('x-axis');
    ylabel('y-axis');
    title('Feasible Region for Inequalities x + y >= 2 and xy - 1 >= 0');
    grid on;
    legend('Feasible Region', 'x + y = 2', 'xy = 1', 'Location', 'Best');
    hold off;

Please see attached.

So, the code defines the range such as linspace(-5, 5, 400) generates 400 points between -5 and 5 for both (x) and (y) and meshgrid(x, y) creates a grid of coordinates from these points. Afterwards, I define the inequalities where inequality1 checks where (x + y) is greater than or equal to 2 and inequality2 checks where the product (xy) is greater than or equal to 1. Then, I combined the inequalities by using the logical AND operator & it is used to find the intersection of the two inequalities, resulting in the feasibleRegion. Finally, a figure is created, and the feasible region is filled with a semi-transparent blue color. Contour lines are added to represent the boundaries of the inequalities, with red for (x + y = 2) and green for (xy = 1) and axis limits, labels, and a title are set to enhance the plot's readability. Hope this helps.

Please let me know if you have any further questions.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

질문:

2024년 6월 29일

댓글:

2024년 8월 16일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by