Results 1 to 2 of 2

Math Help - MATLAB Iterative Methods: URGENT

  1. #1
    Member Maccaman's Avatar
    Joined
    Sep 2008
    Posts
    85

    MATLAB Iterative Methods: URGENT

    Hi there,
    I think that MATLAB is the most annoying program in the world. So it is unfortunate that I have to keep using it for one of my subjects.

    I'm having problems with this question that I have to do. Its long and painful, however, I have done most of it but its not working out for me. Can someone PLEASE help me if you can?

    Here is the question: (there is alot of information to it).
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Member Maccaman's Avatar
    Joined
    Sep 2008
    Posts
    85
    Here is my matlab code for the matrix

    function [a] = bandedsetup(n) % Gives name to mfile to call in cmd window
    e = ones(n,1); % Creates a column vector with n values = 1
    e = 3*e; % Creates a column vector with n values = 3
    a = spdiags([e/3 -e-1 2*e -e-1 e/3], -2:2,n,n); % Entries of matrix a using spdiags function. Here the
    % numbers 1,-4,6,-4,1 that move down the diagonal begins at -2 on the first
    % row of the matrix so that on row 2, the value -4 appears in the first
    % column, and that in row 3, the value 1 appears in the first column, ect..

    % The following lines of code change certain values of the matrix a to give
    % the matrix presented in the question
    a(1,1) = 12;
    a(1,2) = -6;
    a(1,3) = 4/3;
    a(10,8) = 4/3;
    a(10,9) = -6;
    a(10,10) = -12;


    Here is my code for the rhs
    function [rhs, fvector, coeffrhs] = bvector(n)
    L = 10; % L is length of the beam(in metres)
    w = 0.1; % w is the width of the beam (in metres)
    depth = 0.05; % Defines the depth of the beam (in metres)
    d = 7850; % Defines the density of steel (in kg/m^2)
    g=9.81; % Defines the gravitational constant (m/sec^2)
    E = 2*(10^11); % Young's modulus of steel (Newton/m^2)
    h = L/(n); % h as defined in the problem
    I = (w*(h^3))/12; % I defines the area moment of inertia
    f = d*w*depth*g;
    b=zeros(n,1);
    for i =1:n % Determines the applied load for each value of x
    b(i,1) = f; % Weight of the beam loop
    end% Ends the loop
    fvector = b;
    coeffrhs= (h^4)/(E*I);
    rhs= fvector*coeffrhs;

    Here is my code for the Jacobi method

    unction x = jacobi(k) % Gives name to mfile to call in cmd window
    a = bandedsetup(10); % Defines a to be answer produced by bandedsetup
    rhs = bvector(10); % Defines b to be the answer produced by bvector.m
    n = length(rhs); % Defines n to be the length of vector b
    d = diag(a); % Extracts diagonal values in a
    r = a - diag(d); % Produces the remainder
    x = zeros(n,1); % Creates a column vector,x, of length n with values of zero
    for j = 1:k % Beginning of Jacobi method loop
    x = (rhs-r*x)./d; % Defines x for each k
    end% Ends Jacobi method loop


    Now when I run jacobi(k), at say k=100,000 or something like that I keep getting the values of y_i = (NaN)...........................im not sure how to fix this?

    Can anyone help me?
    Thanks in advance to anyone who can.

    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Iterative Methods Convergence (Linear Systems)
    Posted in the Advanced Applied Math Forum
    Replies: 3
    Last Post: January 8th 2011, 10:02 AM
  2. Program for Jacobi iterative method using Matlab.
    Posted in the Advanced Math Topics Forum
    Replies: 2
    Last Post: November 17th 2010, 01:00 AM
  3. Matlab 2nd order methods
    Posted in the Calculus Forum
    Replies: 1
    Last Post: December 2nd 2008, 09:13 AM
  4. Iterative methods
    Posted in the Discrete Math Forum
    Replies: 1
    Last Post: February 13th 2008, 08:24 AM
  5. Iterative methods
    Posted in the Calculus Forum
    Replies: 1
    Last Post: February 11th 2008, 11:58 AM

Search Tags


/mathhelpforum @mathhelpforum