⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 power.m

📁 sareli<matlab科学计算>配套程序
💻 M
字号:
function [lambda,x,iter]=power(A,tol,nmax,x0)%POWER     Numerically evaluate one eigenvalue of a matrix.%   LAMBDA = POWER(A) compute with the power method the %   eigenvalue of A of maximum modulus.%   LAMBDA = POWER(A,TOL,NMAX,X0) uses an absolute error tolerance of TOL %   instead of the default, which is 1.e-6 and a maximum number of iterations%   of NMAX (the default is 100), starting from the initial vector X0.%   [LAMBDA,V,ITER] = POWER(A,TOL,NMAX,X0) also returns the eigenvector%   V such that A*V=LAMBDA*V and the iteration number at which V was computed.[n,m] = size(A);if n ~= m, error('Only for square matrices'); endnarginif nargin == 1   tol = 1.e-06;   x0 = ones(n,1);   nmax = 100;end   x0 = x0/norm(x0); pro = A*x0; lambda = x0'*pro;err = tol + 1; iter = 0while err > tol*abs(lambda) & abs(lambda) ~= 0 & iter <= nmax   x = pro; x = x/norm(x);    pro = A*x; lambdanew = x'*pro;   err = abs(lambdanew - lambda);    lambda = lambdanew;   iter = iter + 1;end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -