Vandermonde Matrix and an Error Vector

In summary, the program uses the inputdlg function to prompt the user to enter a series of numbers. It then calculates the Vandermonde matrix and solves the equation VX = B using mldivide. The residual error is found using the norm function.
  • #1
Siann122
37
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
  • #2
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
 
  • #3
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?
 
  • #4
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
 
  • #5
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.
 

1. What is a Vandermonde Matrix?

A Vandermonde Matrix is a type of matrix that is composed of powers of a given sequence of numbers. It is typically denoted as V and has the form [1, a, a², ..., aⁿ⁻¹; 1, b, b², ..., bⁿ⁻¹; ...; 1, c, c², ..., cⁿ⁻¹], where a, b, c, etc. are the elements of the sequence and n is the number of elements in the sequence.

2. What is the purpose of a Vandermonde Matrix?

A Vandermonde Matrix is commonly used in mathematics, statistics, and engineering for interpolation, polynomial approximation, and solving systems of linear equations. It is also used in cryptography for generating keys and in coding theory for error correction.

3. What is an Error Vector in relation to a Vandermonde Matrix?

An Error Vector is a vector that represents the difference between the actual values and the predicted values in a linear system. In the context of a Vandermonde Matrix, an Error Vector is used to measure the accuracy of the polynomial approximation or the solution to a system of equations.

4. How is a Vandermonde Matrix and an Error Vector used in data analysis?

In data analysis, a Vandermonde Matrix can be used to fit a polynomial curve to a set of data points, making it easier to visualize trends and make predictions. The corresponding Error Vector can then be used to evaluate the accuracy of the fitted curve and make adjustments if necessary.

5. Can a Vandermonde Matrix and an Error Vector be applied to non-linear systems?

Yes, a Vandermonde Matrix and an Error Vector can be applied to non-linear systems by transforming the non-linear equations into linear ones using logarithms or other methods. However, the accuracy of the results may vary depending on the complexity of the non-linear system.

Similar threads

  • Programming and Computer Science
Replies
22
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
938
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Calculus and Beyond Homework Help
Replies
24
Views
795
Replies
39
Views
503
Replies
4
Views
1K
  • Calculus and Beyond Homework Help
Replies
14
Views
594
  • Programming and Computer Science
Replies
2
Views
1K
  • Precalculus Mathematics Homework Help
Replies
32
Views
839
Back
Top