0

I am writing a matlab program to find the convexity of a two variable function using its supremum and infimum

This is the two variable function that i had f(x,y)=(x-2)^2 +(y-2)^2 and both x and y are from 0 to 4.

The Code i wrote for plotting the two variable function is

t= @(x,y) ( (x-2).^2 + (y-2).^2)
x=0:4
y=0:4
[X,Y]=meshgrid(x,y)
surf(X,Y, t(X,Y))
figure 
contour(X,Y, t(X,Y))

for finding the supremum i resolve for all ys for every x and take its supremum g(x)= (x-2)^2 + (y-2)^2 for all ys 0 1 2 3 4

g(0)= 4+ (y-2)^2 for all ys 0 1 2 3 4

g(1)= 1+ (y-2)^2 for all ys 0 1 2 3 4

g(2)= (y-2)^2 for all ys 0 1 2 3 4

g(3)= 1+ (y-2)^2 for all ys 0 1 2 3 4

g(4)= 4+ (y-2)^2 for all ys 0 1 2 3 4

%matlab code for finding supremum
y=0:4
gx_0=4+ (y-2).^2
gx_1=1+ (y-2).^2
gx_2=(y-2).^2
gx_3=(y-2).^2
gx_4=4+ (y-2).^2

x=1:5

plot (x,gx_0)
hold on
plot (x,gx_1)
hold on
plot (x,gx_2)
hold on
plot (x,gx_3)
hold on
plot (x,gx_4)

And for finding the infimum I resolve for all xs for every y and take its infimum

h(y)= (x-2)^2 + (y-2)^2 for all xs 0 1 2 3 4

h(0)= 4+ (x-2)^2 for all xs 0 1 2 3 4

h(1)= 1+ (x-2)^2 for all xs 0 1 2 3 4

h(2)= (x-2)^2 for all xs 0 1 2 3 4

h(3)= 1+ (x-2)^2 for all xs 0 1 2 3 4

h(4)= 4+ (x-2)^2 for all xs 0 1 2 3 4

matlab code

x=0:4
hy_0=4+ (x-2).^2
hy_1=1+ (x-2).^2
hy_2=(x-2).^2
hy_3=(x-2).^2
hy_4=4+ (x-2).^2
y=1:5

plot (y,hy_0)
hold on
plot (y,hy_1)
hold on
plot (y,hy_2)
hold on
plot (y,hy_3)
hold on
plot (y,hy_4)

Is My approach is correct ? Need some expert advice on the problem .

0 Answers0