用matlab求两个变量函数的上界和下界

问题描述

我正在编写一个 matlab 程序,用它的 supremum 和 infimum 找出一个二变量函数的凸性

这是我有 f(x,y)=(x-2)^2 +(y-2)^2 并且 x 和 y 都是从 0 到 4 的两个变量函数。

我为绘制两个变量函数而编写的代码是

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

为了找到上限值,我为每个 x 解析所有 ys 并取其上限值 g(x)= (x-2)^2 + (y-2)^2 对于所有 ys 0 1 2 3 4

g(0)= 4+ (y-2)^2 对于所有 ys 0 1 2 3 4

g(1)= 1+ (y-2)^2 对于所有 ys 0 1 2 3 4

g(2)= (y-2)^2 对于所有 ys 0 1 2 3 4

g(3)= 1+ (y-2)^2 对于所有 ys 0 1 2 3 4

g(4)= 4+ (y-2)^2 对于所有 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)

为了找到下限,我解决了每个 y 的所有 xs 并取其下限

h(y)= (x-2)^2 + (y-2)^2 对于所有 xs 0 1 2 3 4

h(0)= 4+ (x-2)^2 对于所有 xs 0 1 2 3 4

h(1)= 1+ (x-2)^2 对于所有 xs 0 1 2 3 4

h(2)= (x-2)^2 对于所有 xs 0 1 2 3 4

h(3)= 1+ (x-2)^2 对于所有 xs 0 1 2 3 4

h(4)= 4+ (x-2)^2 对于所有 xs 0 1 2 3 4

matlab 代码

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)

我的方法正确吗?需要一些有关该问题的专家建议。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...