最近上数值分析实验课,将做实验用到的代码送给需要帮助的同学。
前两种迭代方法基于计算机数值方法(第二版)(施吉林)212页例题
雅可比迭代法:
code:
import java.util.Random;
class Yabis{
public static void main(String[] args) {
Random random=new Random();
double x1=random.nextDouble();
double x2=random.nextDouble();
double x3=random.nextDouble();
double temp1,temp2,temp3;
int i=1;
System.out.println("雅可比迭代法:x1,x2,x3的初始值是:"+x1+","+x2+","+x3);
while(i<=10){
System.out.println("第"+i+"次迭代");
temp1=x1;
x1=(1.0/8)*(20+3*x2-2*x3);
System.out.println(x1);
temp2=x2;
x2=(1.0/11)*(33-4*temp1+x3);
System.out.println(x2);
temp3=x3;
x3=(1.0/4)*(12-2