设为首页收藏本站

EPS数据狗论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1413|回复: 0

roots求得多项式的所有复根

[复制链接]

13

主题

152

金钱

235

积分

入门用户

发表于 2018-9-20 14:46:22 | 显示全部楼层 |阅读模式
  1. function r = roots(c)
  2. %roots(p)可求得多项式p的所有复根.
  3. %例   x^3+2x^2-3=0
  4. %   求解
  5. %      roots([1 2 0 -3])
  6. %
  7. %ROOTS  Find polynomial roots.
  8. %   ROOTS(C) computes the roots of the polynomial whose coefficients
  9. %   are the elements of the vector C. If C has N+1 components,
  10. %   the polynomial is C(1)*X^N + ... + C(N)*X + C(N+1).
  11. %
  12. %   See also POLY, RESIDUE, FZERO.

  13. %   J.N. Little 3-17-86
  14. %   Copyright (c) 1984-98 by The MathWorks, Inc.
  15. %   $Revision: 5.6 $  $Date: 1997/11/21 23:41:05 $

  16. % ROOTS finds the eigenvalues of the associated companion matrix.

  17. if size(c,1)>1 & size(c,2)>1
  18.     error('Must be a vector.')
  19. end
  20. c = c(:).';
  21. n = size(c,2);
  22. r = zeros(0,1);

  23. inz = find(c);
  24. if isempty(inz),
  25.     % All elements are zero
  26.     return
  27. end

  28. % Strip leading zeros and throw away.  
  29. % Strip trailing zeros, but remember them as roots at zero.
  30. nnz = length(inz);
  31. c = c(inz(1):inz(nnz));
  32. r = zeros(n-inz(nnz),1);

  33. % Polynomial roots via a companion matrix
  34. n = length(c);
  35. if n > 1
  36.     a = diag(ones(1,n-2),-1);
  37.     a(1,:) = -c(2:n) ./ c(1);
  38.     r = [r;eig(a)];
  39. end
复制代码


ROOTS.rar

772 Bytes, 下载次数: 0, 下载积分: 贡献 -1

售价: 1 金钱  [记录]  [购买]

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

本版积分规则

关闭

站长推荐上一条 /1 下一条

客服中心
关闭
在线时间:
周一~周五
8:30-17:30
QQ群:
653541906
联系电话:
010-85786021-8017
在线咨询
客服中心

意见反馈|网站地图|手机版|小黑屋|EPS数据狗论坛 ( 京ICP备09019565号-3 )   

Powered by BFIT! X3.4

© 2008-2028 BFIT Inc.

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