Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Vandermonde Matrix and an Error Vector

  1. Apr 25, 2013 #1
    format long

    n = inputdlg('Please enter a series of numbers seperated by spaces/commas: ')
    numbers = str2num(n{1});
    X = 0
    V = fliplr(vander(numbers))
    r_size = size(V,2);
    c_size = size(V,1);
    B = 1+(r_size./numbers)
    X = B/V

    Here's what I have so far. I've been running the program with n = 5, 15, 20, and basically I want to implement an a way of calculating an error vector using Error = (X - Dt), where Dt = [1, 1, 0, 0, 0, . . . , 0]T.

    I'm not really quite sure how to go about this, and is this a good way to solve VX = B for X? Cheers for any advice guys.
     
  2. jcsd
  3. Apr 25, 2013 #2

    kreil

    User Avatar
    Gold Member

    You should use mldivide, \, when solving equations of the form VX = B. Use mrdivide, /, when the form is XV = B.

    Replace that line with X = V\B

    You can find the residual error from r = B - V*X
     
  4. Apr 25, 2013 #3
    When I use that I get an error saying Matrix Dimensions Must Agree?
     
  5. Apr 25, 2013 #4

    kreil

    User Avatar
    Gold Member

    That's just because B is a row vector instead of a column vector. Try this:

    Code (Text):
    n = inputdlg('Please enter a series of numbers seperated by spaces/commas: ')
    numbers = str2num(n{1})'; % added a ' to make it a column vector
    X = 0;
    V = fliplr(vander(numbers))
    r_size = size(V,2);
    c_size = size(V,1);
    B = 1+(r_size./numbers)
    X = V\B
    For n = 5,10,15,20 I get:

    Code (Text):
    n =

        '5,10,15,20'


    V =

               1           5          25         125
               1          10         100        1000
               1          15         225        3375
               1          20         400        8000


    B =

        1.8000
        1.4000
        1.2667
        1.2000


    X =

        2.6667
       -0.2333
        0.0133
       -0.0003
    The residual is

    Code (Text):
    r = norm(B-V*X)

    r =

       3.8459e-16
     
  6. Apr 25, 2013 #5
    Thanks very much, this works like a charm.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Vandermonde Matrix and an Error Vector
  1. Matrix .* vector? (Replies: 3)

Loading...