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

📄 driver_chandra.m

📁 linear equation routines in matlab
💻 M
字号:
% solve Chandrasekhar H-equation    clear all % reset defauls line thicknesses, .. for graphics   set(0, 'defaultaxesfontsize',12,'defaultaxeslinewidth',0.7,...       'defaultlinelinewidth',0.8,'defaultpatchlinewidth',0.7,...       'defaulttextfontsize',12)% define problem parameters. Pass as global variables to chandra.m  global N c    N = 100;  c = 0.9;  x0 = ones(N,1);  tolf = 1.e-10;  tolx = 1.e-10;  maxit = 100;  % Newton's method  [x, ithist, iflag] = newtnd( 'chandra', x0, tolf, tolx, maxit );   fprintf('\n  Newton''s Method \n ')  fprintf(' iter      || x ||_2          || F(x) ||_2       || s ||_2 \n ')  for i = 1:size(ithist,1)      fprintf('%4d &$ %13.8e $&$ %13.8e $&$ %13.8e $&$ %13.8e $\\\\ \n ', ithist(i,:))  end  mmu = zeros(N,1);  for i = 1:N    mmu(i) = (i-0.5)/N;  end  plot(mmu,x)  xlabel('\mu')  ylabel('H')  title('Solution of the discretized Chandrasekhar H-eqn')  % Finite Difference Newton Method  [x, ithist, iflag] = fdnewtnd( 'chandra', x0, tolf, tolx, maxit );    fprintf('\n  Finite Difference Newton Method \n ')  fprintf(' iter      || x ||_2          || F(x) ||_2       || s ||_2 \n ')  for i = 1:size(ithist,1)      fprintf('%4d &$ %13.8e $&$ %13.8e $&$ %13.8e $&$ %13.8e $\\\\ \n ', ithist(i,:))  end  % Shamanskii's Method  m = maxit;  [x, ithist, iflag] = shamnd( 'chandra', x0, m, tolf, tolx, maxit );    fprintf('\n  Shamanskii''s Method \n ')  fprintf(' iter      || x ||_2          || F(x) ||_2       || s ||_2 \n ')  for i = 1:size(ithist,1)      fprintf('%4d &$ %13.8e $&$ %13.8e $&$ %13.8e $\\\\ \n ', ithist(i,:))  end        % Broyden's Method  B = eye(N);  [x, ithist, iflag] = broyden( 'chandra', B, x0, tolf, tolx, maxit );    fprintf('\n  Broyden''s Method \n ')  fprintf(' iter      || x ||_2          || F(x) ||_2       || s ||_2 \n ')  for i = 1:size(ithist,1)      fprintf('%4d &$ %13.8e $&$ %13.8e $&$ %13.8e $\\\\ \n ', ithist(i,:))  end

⌨️ 快捷键说明

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