Mdel_3 数学建模算法与应用

clc , clear, close all, format long g
% Model three \ mathematics modeling
% some amount to be used  write them in patterns of columns;
r = [0.05, 0.28, 0.21, 0.23, 0.25];
p = [0, 0.01, 0.02, 0.045, 0.065];
q = [0, 0.025, 0.015, 0.055, 0.026]';
M = 10000;
prob = optimproblem('ObjectiveSense', 'min','Description','The min optim');
% Define the decision variables
% because the x_{n+1} equal x_{5} when n equal 4, so the decision variables
% has the structure of 6*1;
x = optimvar('x',6,1,'LowerBound', 0);
%w = 0:0.1:1;
w =[0.766,0.767,0.810,0.811,0.824,0.825,0.962,0.963,1.0];
V=[];  % 风险初始化
Q=[];  % 收益初始化
X=[]; % 决策变量初始化
prob.Constraints.con1 = (1+p)*x(1:end-1)==M;
prob.Constraints.con2 = q(2:end).*x(2:end-1)<=x(end);% I think if not begin from '2',the result is ok  ??????????????
% To solve the problem, we need a circle of 'for'
for i=1:length(w)
    prob.Objective = w(i)*x(end)-(1-w(i))*(r-p)*x(1:end-1,:); % i represent the index, if i ==0.2, so w =0.2.
    [sol, fval] =solve(prob);
    % some data
    xx=sol.x;
    V=[V;max(q.*xx(1:end-1))];% the function 'max' is useful , and the decision variables begin from index '1'from 'end-1',begin x_{5} is useless
    Q=[Q,(r-p)*xx(1:end-1)];X=[X;xx'];
    
%     plot(V,Q,'*-');grid on;
%     xlabel('Risk/yuan');ylabel('Profit/yuan');
end

% The method is also useful in this case, and what we need to keep
% attention is that we should ensure that the elemenets in function 'V';
% Ususally , one symbol error can make whole formula uncorrect!!! I will
% add this error to my CSDN,
% extract values  is in  Q where at last
ind = find(V<=59.4, 1);
sx = X(ind, 1:end-1)
q= V(ind)
% V,Q,X

find函数用在了这里,用于查找x的值。
还有一点需要注意, 那就是for循环与w的结合, 这一点可以借鉴,对于掌握不熟练的我来说是很有帮助的,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值