Solve and plot system in x and y with varying constants e and t

hello,
i am having troubles solving the following problem:
solve and plot for x and y
x+y+e+t>=0
And
x*y-e*t>=0
where x and y are the two variables while e and t are two constants whose values has to vary in a range
i am trying to see the effect of e and t on the system represented by x and y.
basically i would like to obtain on the same graph different curves in x and y for a fixed number of combinations of e and t.
my code so far is:
n= 21;
x = linspace(-100, 100, n);
y = linspace(-100, 100, n);
[X, Y] = meshgrid(x, y);
a = 50;
b = 5;
e = linspace(-a, a, b);
t = linspace(-a, a, b);
Z = zeros(n, n);
for k = 1:b
for s = 1:b
b = X + Y + e(k) + t(s);
d = X.*Y - e(k).*t(s);
for i= 1:n
for j= 1:n
if b(i,j) >= 0
Z(i,j) = d(i,j);
else
Z(i,j) = -1;
end
end
v = [0, 0];
contour(X, Y, Z, v, 'LineWidth', 1.5)
grid on
hold on
end
end
end
Warning: Colon operands must be real scalars. This warning will become an error in a future release.
Warning: Colon operands must be real scalars. This warning will become an error in a future release.
Warning: Colon operands must be real scalars. This warning will become an error in a future release.
Warning: Colon operands must be real scalars. This warning will become an error in a future release.
could anybody please give me any suggestions on how to improve it, as the result so far is not what i expect.
thank you very much

 Akzeptierte Antwort

Torsten
Torsten am 1 Jul. 2024
Verschoben: Torsten am 1 Jul. 2024

0 Stimmen

basically i would like to obtain on the same graph different curves in x and y for a fixed number of combinations of e and t.
Inequalities produce 2d-regions, not 1d-curves as feasible sets. That's why it is difficult or even impossible to find an understandable plot of more than one feasible region for different values of e and t in one graph.

5 Kommentare

i have been a little unclear with my question, sorry.
i want to plot the boundary of the region where both inequalities are satisfied as function of varying e and t. basically i would like to obtain a curve for a defined set of combinations of e and t. that's why i want to plot curves and not 2d regions. is that possible to achieve? what am i doing wrong with my code?
sorry about the misunderstanding, i should have been clearer with what was my objective
E = [100;200];
T = [1;5];
xleft = -25;
xright = 25;
nx = 10000;
x = linspace(xleft,xright,nx);
hold on
for j = 1:numel(E)
e = E(j);
t = T(j);
f1 = @(x) -(x+e+t);
f2 = @(x) e*t./x;
count1 = 0;
count2 = 0;
for i = 1:numel(x)
if x(i) >= 0
count1 = count1 + 1;
x1(count1) = x(i);
px1(count1) = max(f1(x(i)),f2(x(i)));
else
count2 = count2 + 1;
if f1(x(i)) <= f2(x(i))
x2(count2) = x(i);
px21(count2) = f1(x(i));
px22(count2) = f2(x(i));
else
x2(count2) = x(i);
px21(count2) = NaN;
px22(count2) = NaN;
end
end
end
plot(x1,px1,'b')
plot(x2,px21,'r')
plot(x2,px22,'r')
end
hold off
grid on
ylim([-200 100])
thank you.
i have a follow up: how could i plot the same curve but for different values of e and t on the same figure? i tried nesting loops but it didn't work. thanks fo the help
Torsten
Torsten am 2 Jul. 2024
Bearbeitet: Torsten am 2 Jul. 2024
Done (see above).
thank you very much

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 1 Jul. 2024
Verschoben: Walter Roberson am 1 Jul. 2024
for k = 1:b
for s = 1:b
b = X + Y + e(k) + t(s);
You redefine b, which was used as the limit of your for loops.

Community Treasure Hunt

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

Start Hunting!

Translated by