楼主: hxw_0551
1444 3

[问答] 求解matlab高手 [推广有奖]

  • 0关注
  • 6粉丝

已卖:1892份资源

教授

29%

还不是VIP/贵宾

-

威望
0
论坛币
655 个
通用积分
26.7906
学术水平
0 点
热心指数
3 点
信用等级
0 点
经验
233 点
帖子
471
精华
0
在线时间
1907 小时
注册时间
2009-9-9
最后登录
2026-1-21

楼主
hxw_0551 发表于 2011-7-25 18:05:39 |AI写论文
10论坛币
下面是我总matlab的一段程序上截取的一段:
for ii=1:5000;
  if ii==1;   
  runs=1;simulation=0; markup=0; nop=250;
                 params=[0.0146    0.0208         0         0    0.3392    0.0181    0.0605         0    0.4432    2.0093];
  if column==2;  params=[0.0113         0    0.9964         0    0.4269         0    0.0608         0    0.4129    2.2209]; end;
  if column==3;  params=[     0    0.0107         0    1.0101         0    0.1667    0.1290    0.0164    0.2163    3.4214]; end;                              
  if column==4;  params=[     0         0    4.8440         0         0         0    0.0410         0    0.1710    2.0000]; nop=1; end;
  if column==5;  params=[     0         0         0         0         0         0    0.0794    0.0108    0.1000    2.0129]; end;
  if columnr==2; params=[0.0208    0.0028    0.4612    0.3598    0.2862    0.0103    0.0687         0    0.4899    2.1290]; enum=2; end;
  if columnr==3; params=[0.0208    0.0174         0         0    0.2980         0    0.0613         0    0.4980    2.0000]; markup=1; end;
  if columnr==4; params=[0.0089    0.0134    0.6157    0.1986    0.3031         0    0.0815         0    0.3931    2.1478]; nop=25; end;
  if columnr==5; params=[0.0132         0    2.0562    0.0699    0.4698         0    0.0632         0    0.2481    2.1077]; nop=1; end;         
  if columnr==6; params=[0.0208    0.0200    0.2501    1.0392    0.4530    0.0201    0.1138    0.0162    0.3391    2.0000]; period=1; end;
%This initializes the parameters and criterion function. Value is the value function that spits out the criterion given a set of parameters
  criterion=value(params(1,1),params(1,2),params(1,3),params(1,4),params(1,5),params(1,6),params(1,7),params(1,8),params(1,9),params(1,10));
  params1=params; simcoeff1=simcoeff; criterion1=criterion; guess=0;  scalar=0.25; v3=v2;
  
%This is the simulation annealing loop (for ii=2 onwards)
else;
  jj=ii^(1/2); %Scaling parameter for cooling rate
  randn('state',sum(100*clock)); z=[randn(1,2)/(100+jj),randn(1,2)/(2+0.02*jj),randn(1,2)/(10+0.1*jj),randn(1,2)/(20+0.2*jj),randn(1,1)/(10+0.1*jj),randn(1,1)/(2+0.02*jj)];
  if crash==0; params=min(max(params+z+guess,[0 0 0 0 0 0 0 0 0.01 2]),upcap); end; %If not crashed take another guess, if crashed use best guess to reset
  if column==2; params(2)=0; params(4)=0; params(6)=0; elseif column==3; params(1)=0; params(3)=0; params(5)=0; elseif column==4; params(1)=0; params(2)=0; params(5)=0; params(6)=0; elseif column==5; params(1)=0; params(2)=0;  params(3)=0; params(4)=0; params(5)=0; params(6)=0; end;
  criterion=value(params(1,1),params(1,2),params(1,3),params(1,4),params(1,5),params(1,6),params(1,7),params(1,8),params(1,9),params(1,10));
end;

%This shows the results after each loop
disp(' '); disp({'loop',ii,'column',column,'columnr',columnr,'nop',nop,'period',period,'gnum',gnum,'V2(n/2,n/2,1,1)',v2(round(gnum/2),round(hnum/2),1,1),'V2(n/2,n/2,2,2)',v2(round(gnum/2),round(hnum/2),2,2),'gstart',exp(gstart),'gfinish',exp(gfinish),get(0,'diaryfile')});
disp({ 'FCK ','FCL ','lamk','laml','irk ','irl ','mud ','mup ','var ','wagl'}); disp([params;params1]);
disp([simcoeff;simcoeff1;datacoeff]);
disp({'criterion', criterion,'criterion1',criterion1});
disp(datestr(now));
runs=2;
  if isnan(criterion)==1; params=params1; criterion=criterion1; else; %if crashed return to baseline guess.  
  if criterion<criterion1; guess=0.33*(params-params1); params1=params; criterion1=criterion; simcoeff1=simcoeff; v3=v2;  else guess=scalar*(params1-params); params=params1; end; end;                              
end;
这里面的for ,if  end 太多,把我弄混了,能否赐教,将对应的用不同的颜色标注。

最佳答案

异度思维SOA 查看完整内容

告诉你一个非常简单的方法,把这段程序复制到matlab中的M文件里,matlab会自动的给你分清楚循环语句,选择语句的开始和结束
关键词:MATLAB matla atlab Atl Lab MATLAB 高手 求解

本帖被以下文库推荐

沙发
异度思维SOA 发表于 2011-7-25 18:05:40
告诉你一个非常简单的方法,把这段程序复制到matlab中的M文件里,matlab会自动的给你分清楚循环语句,选择语句的开始和结束

藤椅
liuxin9023 发表于 2011-8-1 16:47:38
这个很简单啊 有没有if else的嵌套  就一层有什么好分的啊

板凳
异度思维SOA 发表于 2011-8-2 09:21:31
这个你不要担心,你复制到里面的时候,你会很容易看出逻辑层次,点击一下if,他就能给你找出与它对应的else和if else

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-25 13:16