Vandermonde Matrix and an Error Vector

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 3K views
Siann122
Messages
37
Reaction score
0
format long

n = inputdlg('Please enter a series of numbers separated 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.
 
on Phys.org
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
 
kreil said:
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

When I use that I get an error saying Matrix Dimensions Must Agree?
 
That's just because B is a row vector instead of a column vector. Try this:

Code:
n = inputdlg('Please enter a series of numbers separated 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:
n = 

    '5,10,15,20'V =

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

    1.8000
    1.4000
    1.2667
    1.2000X =

    2.6667
   -0.2333
    0.0133
   -0.0003

The residual is

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

r =

   3.8459e-16
 
kreil said:
That's just because B is a row vector instead of a column vector. Try this:

Code:
n = inputdlg('Please enter a series of numbers separated 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:
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:
r = norm(B-V*X)

r =

   3.8459e-16

Thanks very much, this works like a charm.