声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2386|回复: 3

[绘图技巧] 画出来的图怎么变成直线和不见了???

[复制链接]
发表于 2011-3-22 22:13 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
在模型中
IKK 从0.09-9变化  oed_a 中储存了对应变化的数值, oed_a中各个数值不等,我用断点检测了前十个 结果大致如下
1.0e+021*(2.68 4.48 3.80 3.88 0.21 0.22 0.52 1.69 0.17 0.15)
于是命令plot(IKK, oed_a, r-)  
可为什么画出来的线是直线 或直接看不见,oed_d, oed_e,oed_me情况一样 是不是编程问题??如果是, 应该怎么改! 谢谢您的帮助!

具体编程如下:
  1. clear all
  2. clc;
  3. format long;

  4. IKK_normal=0.9;% initional value of N
  5. for KN=1:100
  6.    
  7.     IKK=IKK_normal*KN/10;
  8.     Xinit=[1.5e-5 0 0 0 0 0.8 0 IKK 0 0]';
  9.     k=[100000 1000 100 10000 50000 200 1000 20000 5000 100 500]';
  10.     sys = mdlInit(@ODESenfun, k , Xinit, zeros(11,10));
  11.     Tspan = 0:60:6000;
  12.     smltn = smltnInit(@ode15s, Tspan);
  13.     n = length(Xinit);
  14.     m = length(k);
  15.     [t, X, S3] = mdlPlay(sys, smltn);

  16.     S2 = S2DParam(S3);
  17.   
  18.   FIM=S2'*S2;
  19. [vec, lam]=eig(FIM);
  20. for j=1:11
  21.     lambda(j)=lam(j,j);
  22. end


  23. %############################optimal##############
  24. oed_a(KN)=trace(inv(FIM));
  25. oed_d(KN)=det(FIM);
  26. oed_e(KN)=min(lambda);
  27. oed_me(KN)=max(lambda)/min(lambda);
  28. %########PLOTING########

  29.    


  30. end


  31. figure
  32.     plot(IKK,oed_a,'r-');
  33.     hold on;
  34.     [a,b]=min(oed_a);
  35.     IKK1=b/10*IKK_normal*ones(size(oed_a));
  36.     plot(IKK1,oed_a,'b--');
  37.     text(0.1,2e-3,['IKK=' num2str(b/10*IKK_normal) '\muM']);
  38.     xlabel('Initial concentration of IKK (\muM)');
  39.     ylabel('Trace(FIM^-^1)');
  40.     legend('A-optimal criterion');
  41.    
  42. figure
  43.     plot(IKK,oed_d,'r-');
  44.     hold on;
  45.     [a,b]=max(oed_d);
  46.     IKK1=b/10*IKK_normal*ones(size(oed_d));
  47.     plot(IKK1,oed_d,'b--');
  48.     text(0.1,10e25,['IKK=' num2str(b/10*IKK_normal) '\muM']);
  49.     xlabel('Initial concentration of IKK (\muM)');
  50.     ylabel('Det(FIM)');
  51.     legend('D-optimal criterion');
  52.    
  53. figure
  54.     plot(IKK,oed_e,'r-');
  55.     hold on;
  56.     [a,b]=max(oed_e);
  57.     IKK1=b/10*IKK_normal*ones(size(oed_e));
  58.     plot(IKK1,oed_e,'b--');
  59.     text(0.1,5e6,['IKK=' num2str(b/10*IKK_normal) '\muM']);
  60.     xlabel('Initial concentration of IKK (\muM)');
  61.     ylabel('\lambda_m_i_n(FIM)');
  62.     legend('E-optimal criterion');
  63.    
  64. figure
  65.     plot(IKK,oed_me,'r-');
  66.     hold on;
  67.     [a,b]=min(oed_me);
  68.     IKK1=b/10*IKK_normal*ones(size(oed_me));
  69.     plot(IKK1,oed_me,'b--');
  70.     text(0.1,8e5,['IKK=' num2str(b/10*IKK_normal) '\muM']);
  71.     xlabel('Initial concentration of IKK (\muM)');
  72.     ylabel('\lambda_m_a_x(FIM)/\lambda_m_i_n(FIM)');
  73.     legend('modified E-optimal criterion');

复制代码
相关子程序:(以下保证正确)
  1. function mdl = mdlInit(ode, theta, x_init, S_init)
  2. % MDLINIT   Initialise the parameters used in the model

  3. % Validate input/output arguments
  4. if nargin~=4
  5.     error('Function requires 4 input arguments');
  6. end

  7. % Initialise model data structure
  8. mdl.ode = ode;
  9. mdl.theta = theta;
  10. mdl.x_init = x_init;
  11. mdl.S_init = S_init;
  12. mdl.thetaAeq = [];
  13. mdl.thetaBeq = [];
复制代码
  1. function [t, X, S] = mdlPlay(mdl, smltn)
  2. % MDLPLAY        Simulate the model over the time span
  3. %
  4. % Returns the simulated states and the sensitivity matrix
  5. %
  6. % [t, X, S] = mdlPlay(mdl, smltn)
  7. %   mdl model data structure
  8. %   smltn   simulation data structure
  9. %   X   2D matrix i,j (states, time) NB this is the transpose of normal
  10. %       return from the solver
  11. %   S   3D matrix i,j,k (states, parameters, time)

  12. % Validate the input/output arguments
  13. if nargin~=2,
  14.     error('Two input arguments are required');
  15. end
  16. if nargout<2 || nargout>3
  17.     error('Two or three output arguments are required');
  18. end

  19. % Initialise the parameters
  20. num_states = length(mdl.x_init);
  21. num_param = length(mdl.theta);

  22. % Reshape the initial parameter/sensitivity values for the ODE simulation)
  23. xs_init = [mdl.x_init; reshape(mdl.S_init, num_states*num_param, 1)];
  24. % Run the ODE simulation
  25. [t, X_S] = feval(smltn.solver, mdl.ode, smltn.tspan, xs_init, [], mdl.theta);

  26. num_time = length(t);
  27. % Reshape the state matrix (states, time)
  28. X = X_S(:,1:num_states)';
  29. % Reshape the sensitivity derivatives (states, parameters, time)
  30. if nargout==3,   
  31.         S = reshape(X_S(:,num_states+1:end)', num_states, num_param, num_time);
  32. end
复制代码
  1. function dx = ODESenfun(t, x, k)

  2. % ODESENFUN        Solve both system dynamic ODEs and Sensitivity Equations
  3. % System Dynamic ODEs
  4. %         x_dot = F*theta
  5. %         S_dot = J*S + F

  6. % Check input and output arguments are correctly supplied
  7. if nargin~=3
  8.     error('Three input arguments are required');
  9. end

  10. numStates = 10;
  11. numPara = 11;
  12. % Calculate the state derivatives
  13. % Need to investigate a way to automatically generate these quantities (from a symbolic model)

  14. %dx(1)=-k1*x(1)*x(6)+km1*x(2)+k4*x(4)-km4*x(1)*x(9)+k6*x(5);
  15. %dx(2)=k1*x(1)*x(6) - km1*x(2) - k2*x(2) + km2*x(3)*x(7);
  16. %dx(3)=k2*x(2) - km2*x(3)*x(7) - k3*x(3)*x(8) + km3*x(4) - k5W*x(3) + km5*x(5);
  17. %dx(4)=k3*x(3)*x(8) - km3*x(4) - k4*x(4) + km4*x(1)*x(9);
  18. %dx(5)=k5W*x(3) - km5*x(5) - k6*x(5);
  19. %dx(6)=-k1*x(1)*x(6) + km1*x(2);
  20. %dx(7)=k2*x(2) - km2*x(3)*x(7);
  21. %dx(8)=-k3*x(3)*x(8) + km3*x(4);
  22. %dx(9)=k4*x(4) - km4*x(1)*x(9);
  23. %dx(10)=k6*x(5);

  24. F = [-x(1)*x(6)      x(2)       0                   0              0           0          x(4)    -x(1)*x(9)         0        0            x(5);
  25.      x(1)*x(6)      -x(2)      -x(2)             x(3)*x(7)         0           0          0          0               0        0             0;
  26.         0             0         x(2)             -x(3)*x(7)    -x(3)*x(8)     x(4)        0          0             -x(3)     x(5)           0;
  27.         0             0         0                   0           x(3)*x(8)     -x(4)      -x(4)     x(1)*x(9)         0        0             0;
  28.         0             0         0                   0              0           0          0          0              x(3)     -x(5)         -x(5);
  29.     -x(1)*x(6)       x(2)       0                   0              0           0          0          0               0        0             0;
  30.         0             0        x(2)            -x(3)*x(7)          0           0          0          0               0        0             0;
  31.         0             0         0                   0           -x(3)*x(8)    x(4)        0          0               0        0             0;
  32.         0             0         0                   0              0           0         x(4)     -x(1)*x(9)         0        0             0;
  33.         0             0         0                   0              0           0          0          0               0        0            x(5);];

  34. dx = F*k;

  35. % Calculate the sensitivity derivatives
  36. % Need to investigate a way to automatically differentiate these quantities (from a symbolic model)
  37. S = reshape(x(numStates+1:end), numStates, numPara);
  38. J = [-k(1)*x(6)-k(8)*x(9)      k(2)               0                     k(7)      k(11)      -k(1)*x(1)     0            0       -k(8)*x(1)     0;
  39.       k(1)*x(6)           -k(2)-k(3)           k(4)*x(7)                 0          0        k(1)*x(1)    k(4)*x(3)      0           0          0;
  40.          0                     k(3)      -k(4)*x(7)-k(5)*x(8)-k(9)      k(6)      k(10)            0     -k(4)*x(3)    -k(5)*x(3)    0          0;
  41.       k(8)*x(9)                 0                k(5)*x(8)           -k(6)-k(7)     0              0        0           k(5)*x(3)  k(8)*x(1)    0;
  42.          0                      0                k(9)                    0       -k(10)-k(11)      0        0            0           0          0;
  43.     -k(1)*x(6)                 k(2)               0                      0          0         -k(1)*x(1)    0            0           0          0;
  44.          0                     k(3)          -k(4)*x(7)                  0          0              0      -k(4)*x(3)     0           0          0;
  45.          0                      0              -k(5)*x(8)                k(6)       0              0        0         -k(5)*x(3)     0          0;
  46.     -k(8)*x(9)                  0                 0                      k(7)       0              0        0            0         -k(8)*x(1)   0;
  47.          0                      0                 0                      0         k(11)           0        0            0           0          0;];
  48.    
  49. dS = J*S+F;

  50. dx((numStates+1):(numStates*(numPara+1))) = reshape(dS,numStates*numPara,1);



复制代码
  1. function S1 = S2DParam(S)
  2. % S2DPARAM  Reshape the sensitivity matrix, S, to a 2D matrix
  3. %   S - 3D matrix (states, param, time)
  4. %   S1 - 2D matrix (states*time, param)

  5. S1 = zeros(size(S,1)*size(S,3), size(S,2));
  6. num_states = size(S,1);
  7. num_time = size(S,3);
  8. for i=1:num_states
  9.     S1((i-1)*num_time+1:i*num_time, :) = shiftdim(S(i, :, :),1)';
  10. end
复制代码
  1. function smltn = smltnInit(solver, tspan)
  2. % Initialize the parameters used in the ODE simulation

  3. % Validate the input/output arguments
  4. if nargin~=2
  5.     error('2 input arguments must be supplied');
  6. end

  7. % Set the data structure's fields
  8. smltn.solver = solver;
  9. smltn.tspan = tspan;
复制代码
如果你有时间 不妨帮我看下, 在此我衷心感谢您的帮助与参与!!
回复
分享到:

使用道具 举报

发表于 2011-3-23 00:06 | 显示全部楼层
1.水平有限, 2.时间有限
想想若是你, LZ会仔细看吗?
想法简化问题, 可能较容易...
看看 提问的智慧!!!!(发帖前请认真阅读)
http://forum.vibunion.com/forum/viewthread.php?tid=21991
 楼主| 发表于 2011-3-23 01:56 | 显示全部楼层
回复 2 # ChaChing 的帖子

谢谢您的帮助 我会仔细学习的
发表于 2011-3-26 21:25 | 显示全部楼层
1.总共6个程序, LZ想会有几个人帮忙看!?
2.LZ都知道plot(IKK, oed_a, r-)有问题了, 为何不检查矩阵变量的大小? ode_a为1*100, IKK为1*1, 当然画出直线!
3.个人水平专业有限, 仅能猜测修改, 在plot前加上IKK=IKK_normal*[1:100]/10; 是会有图的, 不过不知对错!?
4.LZ没发现在求inv时, 一直有warning吗? 建议检查矩阵是否正确?
Warning: Matrix is close to singular or badly scaled.
         Results may be inaccurate. RCOND = 1.461129e-020.
5.很多写法实在不够效率, 如lambda=diag(lam); % for j=1:11, lambda(j)=lam(j,j);end
6.看看精华老帖, 一定有所得
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-8 21:16 , Processed in 0.048021 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表