24小时热门版块排行榜    

CyRhmU.jpeg
查看: 1778  |  回复: 17

ybkooo

至尊木虫 (著名写手)

^^

不共享一下吗?
abcd
11楼2015-01-04 21:48:52
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

吃木头在虫子

新虫 (小有名气)

引用回帖:
11楼: Originally posted by ybkooo at 2015-01-04 21:48:52
不共享一下吗?

可以啊,怎么共享?据大婶说要matlab2012b以上版本才能运行,matlab7.0不行的
12楼2015-01-05 10:30:06
已阅   回复此楼   关注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程序啊,急求。。。
谁能帮我编写个Matlab程序啊,急求。。。-1

  验证:
  因为这是一个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的回帖

ybkooo

至尊木虫 (著名写手)

^^

引用回帖:
12楼: Originally posted by 吃木头在虫子 at 2015-01-05 10:30:06
可以啊,怎么共享?据大婶说要matlab2012b以上版本才能运行,matlab7.0不行的...

楼下的才是大神。我是菜鸟……
abcd
14楼2015-01-05 15:55:28
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

吃木头在虫子

新虫 (小有名气)

送红花一朵
引用回帖:
13楼: Originally posted by NicoleLas at 2015-01-05 14:31:41
我个人觉得先前的应助的结果有点问题,我没有MATLAB,使用Octave算了下,代码与MATLAB差不多。

   代码:
## Copyright (C) 2015 Leiz
##
## This program is free software; you can redistribute it and/o ...

我想知道这到底是什么玩意,太牛了,我都听不懂你在说什么,o(︶︿︶)o 唉,想哭啊
15楼2015-01-06 14:04:01
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

NicoleLas

木虫 (正式写手)

内容已删除
Be water, my friend.
16楼2015-01-06 14:38:50
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

feichedt

银虫 (小有名气)

楼主请问下能共享下代码么。想学习下,谢谢!
17楼2015-01-06 17:58:17
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

--八云--

专家顾问 (知名作家)

博览众家之长,终集百家之短

看来又是一个被数学建模毒害的孩纸啊。。。。。。。
人原本是不死的,后来他创造了死亡,故而人们歌颂他。
18楼2015-01-06 18:16:16
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 吃木头在虫子 的主题更新
信息提示
请填处理意见