Implicit plot with multi variable assumptions (symbolic math)
7 commentaires
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.
Réponses (0)
Voir également
Catégories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!