Question

In: Advanced Math

Use ten iterations of the appropriate MATLAB function, with x^(0)=[0,...,0]', to solve Ax=b (approximately). B) use...

Use ten iterations of the appropriate MATLAB function, with x^(0)=[0,...,0]', to solve Ax=b (approximately).

B) use Gauss-siedel iteration.

C)use SOR with w=1.25, w=1.5, w=1.75,w=1.9, and optimal value if given.

* A=[4,8,0,0;8,18,2,0;0,2,5,1.5;0,0,1.5,1.75] , B=[8;18;0.5;-1.75]. , (optimal w is 1.634.)

Solutions

Expert Solution

%%Matlab code for Gauss Siedel Method and Jacobi method
clear all
close all

%A_matrix is the Coefficient Marix A,b_matrix is the Result Matrix b,
A_matrix=[4,8,0,0;8,18,2,0;0,2,5,1.5;0,0,1.5,1.75];
b_matrix=[8;18;0.5;-1.75];


ww=[1.25 1.5 1.75 1.9];

%total number of iterations
itr=10;

%exact solution
x0=[0 0 0 0];
%displaying the matrix
fprintf('The A matrix is \n')
disp(A_matrix)

fprintf('The b matrix is \n')
disp(b_matrix)

%result for Jacobi method
[x_j]=Jacobi_method(A_matrix,b_matrix,x0,itr);

%result for Gauss Siedel method
[x_g]=Gauss_method(A_matrix,b_matrix,x0,itr);
%Printing the result
fprintf('\n\tThe result using Gauss Siedel Method after 10 iterations is\n');
disp(x_j)

%Printing the result
fprintf('\n\tThe result using Jacobi Method after 10 iterations is\n');
disp(x_g)


for i=1:length(ww)
    %result for Gauss SOR method
    [x_sor]=SOR(A_matrix,b_matrix,x0,ww(i),itr);

    %Printing the result
      fprintf('\n\tThe result using SOR Method for w=%f after 10 iterations is\n',ww(i));
      disp(x_sor')
end

%result for Gauss SOR method
    [x_sor]=SOR(A_matrix,b_matrix,x0,1.634,itr);

    %Printing the result
      fprintf('\n\tThe result using SOR Method for w=1.634 after 10 iterations is\n');
      disp(x_sor')

%Function for Jacobi method
function [x]=Jacobi_method(A,b,x0,itr)
    %Jacobi method
    it=0;
    for nn=1:itr
    %while ea>=conv
        it=it+1;
        for i=1:length(b)
            s=0;
            for j=1:length(b)
                if i~=j
                    s=s+A(i,j)*x0(j);
                end

            end
             x2(i)=(b(i)-s)/A(i,i);
        end
        x0=x2;
    end
    x=x0';
end

%Function for Gauss Siedel method
function [x]=Gauss_method(A,b,x0,itr)
    %Jacobi method
    it=0;
    for nn=1:itr
    %while ea>=conv
        it=it+1;
        for i=1:length(b)
            s=0;
            for j=1:length(b)
                if i~=j
                    s=s+A(i,j)*x0(j);
                end

            end
             x0(i)=(b(i)-s)/A(i,i);
        end
        %x1=x0;
    end
    x=x0';
end


%%Matlab function for Gauss Siedel SOR Method
function [x]=SOR(A,b,x0,lambda,itr)
%inputs are A=matrix A; b=result vector, x0=initial guess
%maxit=maximum iteration;conv=error convergence
%outputs are x=solution matrix, it=maximum iteration; lambda=w for sor
%Gauss Siedel method
k=0;

for nn=1:itr
%while ea>=conv
    k=k+1;
    for i=1:length(b)
        s=0;
        for j=1:length(b)
            if i~=j
                s=s+A(i,j)*x0(j);
            end       
        end
        x11=((lambda*(b(i)-s))/A(i,i))+(1-lambda)*x0(i);
        x0(i)=x11;
    end
end
x=x0;
end

%%%%%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%%%%%%%


Related Solutions

Use ten iterations of the appropriate MATLAB function, with x^(0)=[0,...,0]', to solve Ax=b (approximately). A)use Jacobi...
Use ten iterations of the appropriate MATLAB function, with x^(0)=[0,...,0]', to solve Ax=b (approximately). A)use Jacobi iteration. B) use Gauss-siedel iteration. 1) make sure to use SOR with w=1.25, w=1.5, w=1.75,w=1.9, and optimal value if given. * A=[1,-2,0,0;-2,5,-1,0;0,-1,2,-0.5;0,0,-0.5,1.25]] , B=[-3;5;2;3.5]. , (optimal w is 1.5431.)
write a Matlab function file to solve system Ax=b by using the output of the function...
write a Matlab function file to solve system Ax=b by using the output of the function lufac2a your function should have inputs f=matrix return from lufac2a, piv=array return by lufac2a and b=right hand side of your system.the only output for your system should be x guideline 1.use the column access for the matrix entries 2. do not create any other matrix in your function-get your data directly from the matrix passed into your function 3.do not use Matlab command designed...
Use MuPAD to solve the polynomial equation x3 + 8x2 + ax + 10 = 0 for x in terms of the parameter a,
Use MuPAD to solve the polynomial equation x3 + 8x2 + ax + 10 = 0 for x in terms of the parameter a, and evaluate your solution for the case a = 17. Use MuPAD to check the answer.
Write script in Matlab to solve 1. Y=Ax where X is of dimension n by 1...
Write script in Matlab to solve 1. Y=Ax where X is of dimension n by 1 and A is of dimension m by n. 2. C= A*B where A is of dimension m by p and B is dimension of p by n. So write matlab script to obtain Y and C in above problems.
Exercise 3 Part 1. Solving a system Ax = b **Create a function in MATLAB that...
Exercise 3 Part 1. Solving a system Ax = b **Create a function in MATLAB that begins with: function [C,N]=solvesys(A) [~,n]=size(A); b=fix(10*rand(n,1)) format long We are using format long to display a number in exponent format with 15 digit mantissas. If later on, you will need to switch back to the default format, type and run format The input is an matrix A. If A is invertible, the outputs are the matrix C, whose 3 columns x1, x2, x3 are...
Write a function to solve a system of linear equations of the form Ax= b using...
Write a function to solve a system of linear equations of the form Ax= b using the iterative Gauss-Seidel method. You are free to use any basic MATLAB operation to implement the algorithm (i.e. you may use any combination of loops, indexing, math, etc.), but avoid “built-in” solution methods — you would not be allowed to use the GaussSeidel function if such a function existed. The function must also test for a number of possible issues. If an issue is...
Solve this differential equation using Matlab yy' + xy2 =x , with y(0)=5 for x=0 to...
Solve this differential equation using Matlab yy' + xy2 =x , with y(0)=5 for x=0 to 2.5 with a step size 0.25 (a) Analytical (b) Euler (c) Heun d) 4th order R-K method Display all results on the same graph
1. Solve quadratic equation Ax^2+Bx+C=0 using the quadratic formula x = (-B+ and - sqrt(B^2-4ac)) /...
1. Solve quadratic equation Ax^2+Bx+C=0 using the quadratic formula x = (-B+ and - sqrt(B^2-4ac)) / 2a) and output the two solution with clear explanation could you please do it in MATLAB
!!TRANSLATE TO MATLAB CODE!! INPUT: Function f, endpoint values a, b, tolerance TOL, maximum iterations NMAX...
!!TRANSLATE TO MATLAB CODE!! INPUT: Function f, endpoint values a, b, tolerance TOL, maximum iterations NMAX CONDITIONS: a < b, either f(a) < 0 and f(b) > 0 or f(a) > 0 and f(b) < 0 OUTPUT: value which differs from a root of f(x) = 0 by less than TOL N ← 1 while N ≤ NMAX do // limit iterations to prevent infinite loop c ← (a + b)/2 // new midpoint if f(c) = 0 or (b...
Show to use ode45 built-in function in MATLAB to solve the following ODE problem: dydx=x^2 /...
Show to use ode45 built-in function in MATLAB to solve the following ODE problem: dydx=x^2 / y y(0)=2   Calculate y(x) for 0 ? x ? 20 and compare the results to analytical solution y = sqrt((2x^3 / 3) + 4)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT