## help with nested loop and plot

hello everyone, i need help with the following code.

i am trying to plot the boundary of the region that satisfies the following conditions:

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.

so far i have got (which is working fine for fixed e and t):

n= 101;

x = linspace(-100, 100, n);

y = linspace(-100, 100, n);

[X, Y] = meshgrid(x, y);

Z = zeros(n, n);

e= 10;

t=-25;

B = X + Y + e + t;

D = X.*Y – e.*t;

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

end

v = [0,0];

contour(X,Y,Z,v, ‘LineWidth’, 1.5)

grid on

axis equal

xline(0, ‘Color’, ‘k’, ‘LineWidth’, 0.5);

yline(0, ‘Color’, ‘k’, ‘LineWidth’, 0.5);

now i would like to see the effects of the two constants e and t on the above mentioned boundary. i would like to plot different curves with varying e and t on the same graph but i am having troubles to understand an efficient way to do it.

e and t are two arrays such as linspace(-25, 25, 3), so i want to check how the plot evolves over 3×3 combiations of e and t.

i tried nesting for loops but it didn’t work as i got a blank plot. could anybody please give me any suggestions as to do it with for loops or with any other way?

i know i could do it "manually", changing e and t every time and using hold on to plot the curves on the same figure but it is rather inefficient.

thanks to anyone who will helphello everyone, i need help with the following code.

i am trying to plot the boundary of the region that satisfies the following conditions:

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.

so far i have got (which is working fine for fixed e and t):

n= 101;

x = linspace(-100, 100, n);

y = linspace(-100, 100, n);

[X, Y] = meshgrid(x, y);

Z = zeros(n, n);

e= 10;

t=-25;

B = X + Y + e + t;

D = X.*Y – e.*t;

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

end

v = [0,0];

contour(X,Y,Z,v, ‘LineWidth’, 1.5)

grid on

axis equal

xline(0, ‘Color’, ‘k’, ‘LineWidth’, 0.5);

yline(0, ‘Color’, ‘k’, ‘LineWidth’, 0.5);

now i would like to see the effects of the two constants e and t on the above mentioned boundary. i would like to plot different curves with varying e and t on the same graph but i am having troubles to understand an efficient way to do it.

e and t are two arrays such as linspace(-25, 25, 3), so i want to check how the plot evolves over 3×3 combiations of e and t.

i tried nesting for loops but it didn’t work as i got a blank plot. could anybody please give me any suggestions as to do it with for loops or with any other way?

i know i could do it "manually", changing e and t every time and using hold on to plot the curves on the same figure but it is rather inefficient.

thanks to anyone who will help hello everyone, i need help with the following code.

i am trying to plot the boundary of the region that satisfies the following conditions:

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.

so far i have got (which is working fine for fixed e and t):

n= 101;

x = linspace(-100, 100, n);

y = linspace(-100, 100, n);

[X, Y] = meshgrid(x, y);

Z = zeros(n, n);

e= 10;

t=-25;

B = X + Y + e + t;

D = X.*Y – e.*t;

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

end

v = [0,0];

contour(X,Y,Z,v, ‘LineWidth’, 1.5)

grid on

axis equal

xline(0, ‘Color’, ‘k’, ‘LineWidth’, 0.5);

yline(0, ‘Color’, ‘k’, ‘LineWidth’, 0.5);

now i would like to see the effects of the two constants e and t on the above mentioned boundary. i would like to plot different curves with varying e and t on the same graph but i am having troubles to understand an efficient way to do it.

e and t are two arrays such as linspace(-25, 25, 3), so i want to check how the plot evolves over 3×3 combiations of e and t.

i tried nesting for loops but it didn’t work as i got a blank plot. could anybody please give me any suggestions as to do it with for loops or with any other way?

i know i could do it "manually", changing e and t every time and using hold on to plot the curves on the same figure but it is rather inefficient.

thanks to anyone who will help nested loops, for loop, plot, hold, loops, cycles, grid, meshgrid MATLAB Answers — New Questions