Vandermonde Matrix and an Error Vector

Click For Summary

Discussion Overview

The discussion revolves around the implementation of a Vandermonde matrix in a programming context, specifically focusing on solving the equation VX = B for X and calculating an error vector. Participants explore the appropriate methods for matrix division and error calculation, with examples provided for clarity.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant shares a code snippet for calculating X using a Vandermonde matrix and expresses uncertainty about calculating an error vector.
  • Another participant suggests using mldivide (\,) for solving VX = B and provides a method to find the residual error.
  • A subsequent post raises a concern about an error related to matrix dimensions, indicating that B must be a column vector.
  • A participant responds with a corrected code snippet that transposes the input to ensure B is a column vector, demonstrating the expected output and residual error.
  • Another participant confirms the correction works effectively, expressing satisfaction with the solution.

Areas of Agreement / Disagreement

Participants generally agree on the necessity of using mldivide for the matrix equation and the importance of ensuring correct vector dimensions. However, there is no explicit consensus on the best approach to calculate the error vector, as the initial poster remains uncertain.

Contextual Notes

The discussion includes assumptions about the input format and the handling of matrix dimensions, which may not be universally applicable. The reliance on specific programming functions and their behavior in different contexts is also noted.

Who May Find This Useful

Readers interested in numerical methods, matrix algebra, and programming in environments that handle linear algebra, such as MATLAB, may find this discussion relevant.

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.
 
Physics news 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.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 22 ·
Replies
22
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
7
Views
3K
Replies
2
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 3 ·
Replies
3
Views
15K
  • · Replies 24 ·
Replies
24
Views
4K