24小时热门版块排行榜    

CyRhmU.jpeg
查看: 1778  |  回复: 17
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

吃木头在虫子

新虫 (小有名气)

[求助] 谁能帮我编写个Matlab程序啊,急求。。。

编写出matlab程序,能生成三维网格图的程序,我需要程序和图,多谢。。。。函数及条件如下图,这是优化设计方面的问题

谁能帮我编写个Matlab程序啊,急求。。。
0))1T7L`0IY(YKF6W}N41OD.png
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

NicoleLas

木虫 (正式写手)


吃木头在虫子: 回帖置顶 2015-01-06 14:04:57
我个人觉得先前的应助的结果有点问题,我没有MATLAB,使用Octave算了下,代码与MATLAB差不多。

   代码:
CODE:
## Copyright (C) 2015 Leiz
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, see
## <http://www.gnu.org/licenses/>.

## demoSurf

## Author: Leiz <Leiz@LEIZ-PC>
## Created: 2015-01-05

clear all
clc
x1 = linspace( 0, 6, 50 );
x2 = linspace( 0, 6, 50 );
[ xx1, xx2 ] = meshgrid( x1, x2 );
tempx1 = xx1;
tempx2 = xx2;
tempx1( xx1 + xx2 > 6 ) = NaN;
tempx1( -xx1 + 2*xx2 > 2 ) = NaN;
tempx2( xx1 + xx2 > 6 ) = NaN;
tempx2( -xx1 + 2*xx2 > 2 ) = NaN;
fx = -2*tempx1 - 6*tempx2 + tempx1.^2 - 2*tempx1.*tempx2 + 2*tempx2.^2;

figure(1)
surf( tempx1, tempx2, fx );
h1 = get( gcf, "currentaxes" );
set( h1, "linewidth", 2 );
xlabel( 'x_{1}' );
ylabel( 'x_{2}' );
zlabel( 'f(x)' );
title( 'Surface of f(x) = -2x_{1} - 6x_{2} + x_{1}^{2} - 2x_{1}x_{2} + 2x_{2}^{2}' );
view( -60, 30 );
print( "demoSurf.png", "-dpng" );

figure(2)
contour( tempx1, tempx2, fx, 20 );
h2 = get( gcf, "currentaxes" );
set( h2, "linewidth", 2 );
axis( [ 0, 6, 0, 3 ] );
xlabel( 'x_{1}' );
ylabel( 'x_{2}' );
title( 'Contour of f(x) = -2x_{1} - 6x_{2} + x_{1}^{2} - 2x_{1}x_{2} + 2x_{2}^{2}' );
print( "demoContour.png", "-dpng" );

结果:
谁能帮我编写个Matlab程序啊,急求。。。-1
谁能帮我编写个Matlab程序啊,急求。。。-2

  验证:
  因为这是一个QP问题,Octave这方面求解的函数有一些不过我为了简便使用了LINGO来求解。
  code:
CODE:
MIN = -2*X1 - 6*X2 + X1^2 - 2*X1*X2 + 2*X2^2;
X1 + X2 <= 6;
-X1 + 2*X2 <= 2;

solution:
CODE:
  Global optimal solution found.
  Objective value:                       -15.11111111082
  Infeasibilities:                        0.000000000000
  Total solver iterations:                             6
  Elapsed runtime seconds:                          0.02
  Model is convex quadratic

  Model Class:                                        QP

  Total variables:                      2
  Nonlinear variables:                  2
  Integer variables:                    0

  Total constraints:                    3
  Nonlinear constraints:                1

  Total nonzeros:                       6
  Nonlinear nonzeros:                   3

                    Variable                 Value              Reduced Cost
                          X1        3.333333333380           0.3832140051194E-10
                          X2        2.666666666506           0.4779796153731E-10

                         Row          Slack or Surplus            Dual Price
                           1       -15.11111111082           -1.000000000000
                           2       0.1140998406868E-09        1.111111111122
                           3       0.3667064429891E-09       0.4444444448297

» 本帖已获得的红花(最新10朵)

Be water, my friend.
13楼2015-01-05 14:31:41
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 18 个回答

吃木头在虫子

新虫 (小有名气)

没有人会吗?等待大婶出现啊
2楼2015-01-04 20:29:38
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

嘻哈学士

银虫 (小有名气)

【答案】应助回帖

感谢参与,应助指数 +1
引用回帖:
2楼: Originally posted by 吃木头在虫子 at 2015-01-04 20:29:38
没有人会吗?等待大婶出现啊

见图
谁能帮我编写个Matlab程序啊,急求。。。-3
untitledq.jpg

3楼2015-01-04 20:44:45
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

吃木头在虫子

新虫 (小有名气)

引用回帖:
3楼: Originally posted by 嘻哈学士 at 2015-01-04 20:44:45
见图

untitledq.jpg
...

上面的那段程序输入到matlab就能输出该图形吗?附加的约束条件加了没?我想要程序,弄好再加你20金币
4楼2015-01-04 20:48:03
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
信息提示
请填处理意见