公告:网站程序已升级到1.8.3,修复了提问时可能报错的问题,请清除浏览器缓存
2019-11-10

欢迎来到 Mathematica 问答社区

提问时请贴上文本代码

语法高亮:在编辑器中点击

被禁止的话题:广告破解

请阅读:《提问的智慧》

备用域名:mma.ooo

支持LaTex数学公式
行内公式标识符:\$ 或“$\backslash ($”+“$\backslash )$”,
行间公式标识符:\$\$ 或 “$\backslash [$”+“$\backslash ]$”

社区建议QQ群:365716997

分类

0 投票
539 浏览
f[x1_, x2_, x3_, x4_] := (((x1^2 + 2 x2^2 + 3 x3^2 + 2 x4^2) - 8)/
242)^2 + ((6 x1*E^(x1/4) + 6 x2*E^(x2/4) + 8 x3*E^(x3/4) +
7 x4*E^(x4/4) - 34.6)/
465)^2 + ((10^(-5)*1000^1.5*(x1 + E^(x1/4)) +
2.3*10^(-5)*1000^1.5*(x2 + E^(x2/4)) +
0.3*10^(-5)*1000^1.5*(x3 + E^(x3/4)) +
2.3*10^(-5)*1000^1.5*(x4 + E^(x4/4)) - 114)/
286)^2 + (((1 - (1 - (1 - 1/E)^x1) (1 - (1 - 1/E)^
x2) (1 - (1 - 1/E)^x3) (1 - (1 - 1/E)^x4)) - 0.04)/0.21)^2
g[x1_, x2_, x3_, x4_] :=
1 <= x1 <= 10 && 1 <= x2 <= 10 && 1 <= x3 <= 10 && 1 <= x4 <= 10 &&
x1 \[Element] Integers && x2 \[Element] Integers &&
x3 \[Element] Integers && x4 \[Element] Integers

h[x1_, x2_, x3_, x4_] :=
Minimize[f[x1, x2, x3, x4], g[x1, x2, x3, x4], {x1, x2, x3, x4}]
t[{x1_, x2_, x3_, x4_}] := (x1^2 + 2 x2^2 + 3 x3^2 + 2 x4^2) <=
   250 && (6 x1*E^(x1/4) + 6 x2*E^(x2/4) + 8 x3*E^(x3/4) +
     7 x4*E^(x4/4)) <=
   500 && (10^(-5)*1000^1.5*(x1 + E^(x1/4)) +
     2.3*10^(-5)*1000^1.5*(x2 + E^(x2/4)) +
     0.3*10^(-5)*1000^1.5*(x3 + E^(x3/4)) +
     2.3*10^(-5)*1000^1.5*(x4 + E^(x4/4))) <=
   400 && (1 - (1 - (1 - 1/E)^x1) (1 - (1 - 1/E)^x2) (1 - (1 - 1/E)^
         x3) (1 - (1 - 1/E)^x4)) <= 0.25

 

 

 

我的目的是求f[x1,x2,x3,x4]在满足g[x1,x2,x3,x4]和t[x1,x2,x3,x4]下的最小值
我打算的做法是先求出f的一个最小值判断是否满足t,如果满足就输出,不满足就把这个点去掉再求最小值,求指教这个怎么实现?(我不知道能不能不用循环直接算的,但是Minimize的限制语句好像只能是多项式函数)

For[h[x1, x2, x3,
  x4], (x1^2 + 2 x2^2 + 3 x3^2 + 2 x4^2) >
   250 && (6 x1*E^(x1/4) + 6 x2*E^(x2/4) + 8 x3*E^(x3/4) +
     7 x4*E^(x4/4)) >
   500 && (10^(-5)*1000^1.5*(x1 + E^(x1/4)) +
     2.3*10^(-5)*1000^1.5*(x2 + E^(x2/4)) +
     0.3*10^(-5)*1000^1.5*(x3 + E^(x3/4)) +
     2.3*10^(-5)*1000^1.5*(x4 + E^(x4/4))) >
   400 && (1 - (1 - 1/E)^x1) (1 - (1 - 1/E)^x2) (1 - (1 - 1/E)^
       x3) (1 - (1 - 1/E)^x4) > 0.25
 , ,
 If[t[x1, x2, x3, x4],
  Print[x1, x2, x3, x4], {Print[x1, x2, x3, x4],
   g[y1, y2, y3, y4] =
    Complement[
     g[y1, y2, y3, y4], {y1 = x1 && y2 = x2 && y3 = x3 && y4 = x4}]}]]

这个不对

 

 

抱歉刚才发布的打错了

t函数是t[{x1_, x2_, x3_, x4_}] := (x1^2 + 2 x2^2 + 3 x3^2 + 2 x4^2) <=
   250 && (6 x1*E^(x1/4) + 6 x2*E^(x2/4) + 8 x3*E^(x3/4) +
     7 x4*E^(x4/4)) <=
   500 && (10^(-5)*1000^1.5*(x1 + E^(x1/4)) +
     2.3*10^(-5)*1000^1.5*(x2 + E^(x2/4)) +
     0.3*10^(-5)*1000^1.5*(x3 + E^(x3/4)) +
     2.3*10^(-5)*1000^1.5*(x4 + E^(x4/4))) <=
   400 && (1 - (1 - (1 - 1/E)^x1) (1 - (1 - 1/E)^x2) (1 - (1 - 1/E)^
         x3) (1 - (1 - 1/E)^x4)) <= 0.25
用户: zzz7857638 (11 分)
修改于 用户:zzz7857638

1个回答

+1 投票

你这问题完全没必要使用Minimize。

首先修改f和t的形式,仅仅是把输入变量的形式变了,加个括号。

Clear[f, t]
(*修改t和f的输入形式*)

t[{x1_, x2_, x3_, x4_}] := (x1^2 + 2 x2^2 + 3 x3^2 + 2 x4^2) <= 
   250 && (6 x1*E^(x1/4) + 6 x2*E^(x2/4) + 8 x3*E^(x3/4) + 
     7 x4*E^(x4/4)) <= 
   500 && (10^(-5)*1000^1.5*(x1 + E^(x1/4)) + 
     2.3*10^(-5)*1000^1.5*(x2 + E^(x2/4)) + 
     0.3*10^(-5)*1000^1.5*(x3 + E^(x3/4)) + 
     2.3*10^(-5)*1000^1.5*(x4 + E^(x4/4))) <= 
   400 && (1 - (1 - 1/E)^x1) (1 - (1 - 1/E)^x2) (1 - (1 - 1/E)^
       x3) (1 - (1 - 1/E)^x4) <= 0.25
f[{x1_, x2_, x3_, 
   x4_}] := (((x1^2 + 2 x2^2 + 3 x3^2 + 2 x4^2) - 8)/
     242)^2 + ((6 x1*E^(x1/4) + 6 x2*E^(x2/4) + 8 x3*E^(x3/4) + 
       7 x4*E^(x4/4) - 34.6)/
     465)^2 + ((10^(-5)*1000^1.5*(x1 + E^(x1/4)) + 
       2.3*10^(-5)*1000^1.5*(x2 + E^(x2/4)) + 
       0.3*10^(-5)*1000^1.5*(x3 + E^(x3/4)) + 
       2.3*10^(-5)*1000^1.5*(x4 + E^(x4/4)) - 114)/
     286)^2 + (((1 - (1 - (1 - 1/E)^x1) (1 - (1 - 1/E)^
             x2) (1 - (1 - 1/E)^x3) (1 - (1 - 1/E)^x4)) - 0.04)/
     0.21)^2

其次,根据g的限定,也就10000种可能,直接暴力枚举所有可能。

all = Tuples[Range[10], 4];
possible = Select[all, t];
data = SortBy[{f@#, #} & /@ possible, First];
First@data

 

用户: 苹果 (2.2k 分)
f[{x1_, x2_, x3_, x4_}] 里面的几个变量为什么要加括号呢?
方便后续操作。例如a={1,2}; f[x_,y_]:=x+y; f@@a可以,但是不方便。
t[{x1_, x2_, x3_, x4_}] := (x1^2 + 2 x2^2 + 3 x3^2 + 2 x4^2) <=
   250 && (6 x1*E^(x1/4) + 6 x2*E^(x2/4) + 8 x3*E^(x3/4) +
     7 x4*E^(x4/4)) <=
   500 && (10^(-5)*1000^1.5*(x1 + E^(x1/4)) +
     2.3*10^(-5)*1000^1.5*(x2 + E^(x2/4)) +
     0.3*10^(-5)*1000^1.5*(x3 + E^(x3/4)) +
     2.3*10^(-5)*1000^1.5*(x4 + E^(x4/4))) <=
   400 && (1 - (1 - 1/E)^x1) (1 - (1 - 1/E)^x2) (1 - (1 - 1/E)^
       x3) (1 - (1 - 1/E)^x4) > 0.75
f[{x1_, x2_, x3_,
   x4_}] := (((x1^2 + 2 x2^2 + 3 x3^2 + 2 x4^2) - 8)/
     242)^2 + ((6 x1*E^(x1/4) + 6 x2*E^(x2/4) + 8 x3*E^(x3/4) +
       7 x4*E^(x4/4) - 34.6)/
     465)^2 + ((10^(-5)*1000^1.5*(x1 + E^(x1/4)) +
       2.3*10^(-5)*1000^1.5*(x2 + E^(x2/4)) +
       0.3*10^(-5)*1000^1.5*(x3 + E^(x3/4)) +
       2.3*10^(-5)*1000^1.5*(x4 + E^(x4/4)) - 114)/
     286)^2 + (((1 - (1 - (1 - 1/E)^x1) (1 - (1 - 1/E)^
             x2) (1 - (1 - 1/E)^x3) (1 - (1 - 1/E)^x4)) - 0.04)/0.21)^2
all = Tuples[Range[10], 4];
possible = Select[all, t];
data = SortBy[{f@#, #} & /@ possible, First];
First@data


First::first: "{} has a length of zero and no first element"  就算不出来了
就那个t 的最后改动了一小下
@苹果: 明白了,谢谢。
...