楼主: neptune225
4846 8

Matlab二次规划编程 [推广有奖]

  • 0关注
  • 0粉丝

初中生

95%

还不是VIP/贵宾

-

威望
0
论坛币
1 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
184 点
帖子
4
精华
0
在线时间
28 小时
注册时间
2009-3-8
最后登录
2014-5-6

楼主
neptune225 发表于 2009-9-14 22:54:07 |AI写论文
5论坛币
function [re1,re2]=minvar(x,y)
% calculate the optimal coefficient by minimize the variance between x and
% c*y. That is var(x-c*y).
% Input parameters:
%       x: the raw data
%       y: the benchmark for optimization
% Output parameters:
%     re1: the R^2 (first column)
%          the parameters c (rest of every row)
%     re2: the ESS
% x should be a array or a matrix
% y should be a matrix,the form is either(1,b1,b2...),or(b1,b2...)
% x and y should have the same dimension
[m,n]=size(y);
[a,b]=size(x);
lb = zeros(1,n);        % Set lower bounds
if y(:,1) == ones(m,1)  % if b is (1,b1,b2...), the corresponding lower bound is empty
    lb(1,1)=-inf;
end
ub = [ ];               % No upper bounds
Aeq= ones(1,n);         % Set equality constrain
if y(:,1) == ones(m,1)  % if b is (1,b1,b2...), the Aeq is (0,1,1...)
    Aeq(1,1)=0;
end
beq=1;
options = optimset('LargeScale','off');
mm1 = zeros(b,n+1);
mm2 = zeros(a,b);
for i =1:b
    k = x(:,i);
    [v,fval] =  lsqlin(y,k,[ ],[ ],Aeq,beq,lb,ub);
    mm1(i,2:n+1) = v';          % calculate the optimal coefficient c
    tssk=sum((k-mean(k)).^2);
    essk=sum((k-y*v).^2);  
    mm1(i,1)=1-essk/tssk;    % calculate the R^2 value
    mm2(:,i)=(k-y*v).^2;              % calculate the ESS
end
re1 = mm1;
re2 = mm2;



为什么运行后出现: Error: Function definitions are not permitted at the prompt or in scripts.

关键词:MATLAB matla atlab 二次规划 Lab MATLAB 二次规划

沙发
ping7733 发表于 2009-9-15 17:09:25
不可以在脚本窗运行,要在editor里。
已有 1 人评分经验 论坛币 收起 理由
Xaero + 40 + 40 我很赞同

总评分: 经验 + 40  论坛币 + 40   查看全部评分

藤椅
xifengpo126 发表于 2009-9-17 22:09:36
真是太感谢楼主了 无私奉献

板凳
liqihua463528 发表于 2010-5-11 12:25:04
editor里具体怎么操作啊,请楼主说具体点啊 ?

报纸
liuxin9023 发表于 2010-5-11 14:24:15
函数定义要单独放在一个文件里

地板
tulipsliu 在职认证  发表于 2010-5-11 17:54:17
if y(:,1) == ones(m,1)  % if b is (1,b1,b2...), the corresponding lower bound is empty
    lb(1,1)=-inf;
end

本文来自: 人大经济论坛 详细出处参考:http://www.pinggu.org/bbs/viewth ... &from^^uid=418684
循环里的 -inf 是什么?
劳动经济学

7
ywh19860616 发表于 2010-5-11 17:59:00
循环里的 -inf 是什么?
表示负无穷大

8
tulipsliu 在职认证  发表于 2010-5-11 18:52:40
我知道是无穷大
我是问MATLAB里可以这样表示?
劳动经济学

9
tulipsliu 在职认证  发表于 2010-5-11 18:53:24
先用记事本把这个程序保存下来
我跑一遍试试
看看是哪里错了
劳动经济学

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-29 12:51