Implicit plot with multi variable assumptions (symbolic math)

4 ビュー (過去 30 日間)
LUCA D'AMBROSIO
LUCA D'AMBROSIO 2024 年 6 月 29 日
コメント済み: Umar 2024 年 8 月 16 日
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 件のコメント
Torsten
Torsten 2024 年 6 月 30 日
編集済み: Torsten 2024 年 6 月 30 日
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')
Umar
Umar 2024 年 8 月 16 日

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 件)

カテゴリ

Help Center および File ExchangeGet Started with Symbolic Math Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by