1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MATLAB Gaussian Elimination

  1. Sep 23, 2013 #1
    1. The problem statement, all variables and given/known data
    I am writing a GE program and i think i have that correct. I have a matrix and i am trying to find the correct answer. I am not sure where i am going wrong.


    2. Relevant equations



    3. The attempt at a solution

    %GE with no pivoting
    function x=ge_nopivot(A,b)
    n=length(A); Ab=[A b];
    for k=1 : n-1
    for i=k+1 : n
    ratio=Ab(i,k)/Ab(k,k);
    Ab(i,k : n+1)= Ab(i,k : n+1)-ratio*Ab(k,k : n+1);
    end
    end
    %back subsitution
    x=zeros(n,1); x(n)=Ab(n,n+1)/Ab(n,n);
    for i=n-1 : -1 : 1
    x(i)=(Ab(i,n+1)-Ab(i,i+1:n)*x(i+1 : n))/Ab(i,i);
    end



    A=[-cosd(30) 0 cosd(60) 0 0 0; -sind(30) 0 -sind(60) 0 0 0; cosd(30) 1 0 1 0 0; sind(30) 0 0 0 1 0; 0 1 cosd(60) 0 0 0; 0 0 sind(60) 0 0 1]; b=[0;2000;0;0;0;0];
    >> n=length(A)

    n =

    6

    >> Ab=[A b]

    Ab =

    1.0e+03 *

    -0.0009 0 0.0005 0 0 0 0
    -0.0005 0 -0.0009 0 0 0 2.0000
    0.0009 0.0010 0 0.0010 0 0 0
    0.0005 0 0 0 0.0010 0 0
    0 0.0010 0.0005 0 0 0 0
    0 0 0.0009 0 0 0.0010 0

    >> x=ge_nopivot(A,b)
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?



Similar Discussions: MATLAB Gaussian Elimination
  1. MATLAB Function (Replies: 0)

Loading...