31.利用linprog 解决 投资问题(matlab程序)

本文讲述了使用MATLAB内置函数linprog解决线性规划问题的过程,涉及输入参数、算法选择、求解步骤和结果分析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.简述

      

 

语法:[X,FVAL] = linprog(f,a,b,Aeq,Beq,LB,UB,X0);

    X 为最终解 , FVAL为最终解对应的函数值
    *注意:求最大值时,结果FVAL需要取反*
    
    f 为决策函数的系数矩阵。
    *注意:当所求为最大值时,系数矩阵需要取反*
    
    a 为约束条件中不等式组的系数矩阵 ,a的列数等于f的列数
    *注意:当不等号为  > 或  ≥ 时,矩阵需要取反*
    
    b 为约束条件中不等式组右边的值
    *注意:当不等号为  > 或  ≥ 时,矩阵需要取反*
    
    Aeq 为约束条件中等式组的系数矩阵 ,Aeq的列数等于f的列数
    
    Beq 为约束条件中等式组右边的值
    
    LB、UB 是解的范围
    
    X0  为初始值
 

2.代码

 

主程序:

%%   投资问题
f=[-0.2;-0.12;-0.09;-0.14];
A=[1,-1,-1,-1;0,-1,-1,1];
b=[0;0];
Aeq=[1,1,1,1];
beq=1;
l=[0 0 0];
u=[1 1 1];
[xo,yo,exitflag]=linprog(f,A,b,Aeq,beq,l,u)

 

 

子程序:

function [x,fval,exitflag,output,lambda]=linprog(f,A,B,Aeq,Beq,lb,ub,x0,options)
%LINPROG Linear programming.
%   X = LINPROG(f,A,b) attempts to solve the linear programming problem:
%
%            min f'*x    subject to:   A*x <= b
%             x
%
%   X = LINPROG(f,A,b,Aeq,beq) solves the problem above while additionally
%   satisfying the equality constraints Aeq*x = beq. (Set A=[] and B=[] if
%   no inequalities exist.)
%
%   X = LINPROG(f,A,b,Aeq,beq,LB,UB) defines a set of lower and upper
%   bounds on the design variables, X, so that the solution is in
%   the range LB <= X <= UB. Use empty matrices for LB and UB
%   if no bounds exist. Set LB(i) = -Inf if X(i) is unbounded below;
%   set UB(i) = Inf if X(i) is unbounded above.
%
%   X = LINPROG(f,A,b,Aeq,beq,LB,UB,X0) sets the starting point to X0. This
%   option is only available with the active-set algorithm. The default
%   interior point algorithm will ignore any non-empty starting point.
%
%   X = LINPROG(PROBLEM) finds the minimum for PROBLEM. PROBLEM is a
%   structure with the vector 'f' in PROBLEM.f, the linear inequality
%   constraints in PROBLEM.Aineq and PROBLEM.bineq, the linear equality
%   constraints in PROBLEM.Aeq and PROBLEM.beq, the lower bounds in
%   PROBLEM.lb, the upper bounds in  PROBLEM.ub, the start point
%   in PROBLEM.x0, the options structure in PROBLEM.options, and solver
%   name 'linprog' in PROBLEM.solver. Use this syntax to solve at the
%   command line a problem exported from OPTIMTOOL.
%
%   [X,FVAL] = LINPROG(f,A,b) returns the value of the objective function
%   at X: FVAL = f'*X.
%
%   [X,FVAL,EXITFLAG] = LINPROG(f,A,b) returns an EXITFLAG that describes
%   the exit condition. Possible values of EXITFLAG and the corresponding
%   exit conditions are
%
%     3  LINPROG converged to a solution X with poor constraint feasibility.
%     1  LINPROG converged to a solution X.
%     0  Maximum number of iterations reached.
%    -2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

素馨堂

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值