jacobi, gauss-seidel, and SOR
来源:互联网 发布:科目一挂机软件 编辑:程序博客网 时间:2024/05/29 04:07
JACOBI
% it there any bug?? who knows...function [ x ] = jacobi()%A = [8,-3,2;4,11,-1;6,3,12];%b = [20,33,36];A = [0.8 -0.4 0; -0.4 0.8 -0.4; 0 -0.4 0.8];b = [41; 25; 105];error_tolerance = 0.05;max_iter = 500;error = 1;[m, n] = size(A);x_old = zeros(m, 1);x_new = zeros(m, 1);iter = 0;while (error > error_tolerance && iter < max_iter) for i = 1: m % rows summation = 0; for j = 1: n % columns if (i ~= j) summation = summation + A(i, j) * x_old(j); end; end; x_new(i) = (b(i) - summation) / A(i, i); end; error = norm(x_old - x_new)/norm(x_new); x_old = x_new; iter = iter + 1;end;if iter == max_iter fprintf('The solution diverge\n');end;x = x_new;fprintf('The totol iteration times: %d\n', iter);
gauss-seidel and SOR
% it there any bug?? who knows...function [ x ] = G_S() % can use A and b as the input%A = [8,-3,2;4,11,-1;6,3,12];%b = [20,33,36];A = [0.8 -0.4 0; -0.4 0.8 -0.4; 0 -0.4 0.8];b = [41; 25; 105];error_tolerance = 0.000001; % this tolerance is too big...max_iter = 500;error = 1;[m, n] = size(A);x_old = zeros(m, 1);x_new = zeros(m, 1);iter = 0;omega = 1; % when omega == 1, it is gauss-seidel method % SOR --Successive over relaxation method.while (error > error_tolerance && iter < max_iter) for i = 1: m % rows summation = 0; for j = 1: n % columns if (i ~= j) summation = summation + A(i, j) * x_new(j); x_new(i) = (b(i) - summation) / A(i, i); x_new(i) = omega * x_new(i) + (1-omega) * x_old(i); end; end; %x_new(i) = (b(i) - summation) / A(i, i); end; error = norm(x_old - x_new)/norm(x_old); x_old = x_new; iter = iter + 1;end;if iter == max_iter fprintf('The solution diverge\n');end;x = x_new;fprintf('The totol iteration times: %d\n', iter);
0 0
- jacobi, gauss-seidel, and SOR
- Jacobi Gauss-Seidel迭代法
- Matlab实现——Jacobi Iteration and Gauss-Seidel Iteration
- Jacobi迭代法 Gauss-Seidel迭代法
- Jacobi迭代法 Gauss-Seidel迭代法
- Gauss–Seidel方法和Jacobi 方法
- Jacobi迭代法与Gauss-Seidel迭代法
- Jacobi迭代法与Gauss-Seidel迭代法
- #公式与实现# Jacobi迭代 Gauss-Seidel迭代
- Jacobi and Guass-Seidel Iteration Update
- Gauss-Seidel解线性方程组
- 分别用雅可比(Jacobi)迭代法和高斯—塞德尔(Gauss—Seidel)迭代法求解线性方程组
- 求解线性方程组--Gauss-Seidel迭代法
- Matlab code for Gauss-Seidel and Successive over relaxation iterative methods
- Gauss-Seidel迭代法求方程组的解
- Jacobi迭代与SOR迭代求解希尔伯特矩阵
- 数值计算 && 实验8 && Gauss-Seidel迭代法求解线性方程组
- 数值分析 Gauss-Seidel迭代法求解线性方程组 MATLAB程序实现
- TCP/IP协议族(一)
- 集群默认只使用每个节点8G内存的修改方法
- Project Eluer - 15
- Android 开发中出现java.lang.NullPointerException
- Android编译系统详解(一)——build/envsetup.sh
- jacobi, gauss-seidel, and SOR
- 报错:1130-host ... is not allowed to connect to this MySql server 开放mysql远程连接 不使用localhost
- OC浅拷贝和深拷贝
- 【Android】Back Home键监听
- unity中摄像机跟随主角,摄像机穿墙,射线碰撞检测,摄像机穿墙跟随
- LeetCode: Binary Tree Preorder Traversal
- 人品计算器
- Sicily 1294 高级机密
- cocos2dx之onEnter,onExit