[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Newbie question solving lin sys
From: |
William Lash |
Subject: |
Re: Newbie question solving lin sys |
Date: |
Fri, 27 Dec 2002 16:15:28 -0600 |
Whenever you type in the numbers for you calculation in s you are
losing precision. Instead of typing in:
>octave:55> 22 + 129.32*s - 330.01*s**2 + 356.74*s**3 - 211.74*s**4 +
>77.512*s**5 - 18.446*s**6 + 2.9092*s**7 - 0.30191*s**8 + 0.019818*s**9 -
>0.0007457*s**10 + 0.00001225*s**11
Try the following:
x(1)+x(2)*s+x(3)*s**2+x(4)*s**3+x(5)*s**4+x(6)*s**5+x(7)*s**6+x(8)*s**7+x(9)*s**8+x(10)*s**9+x(11)*s**10+x(12)*s**11
There are better ways to write this in octave, one way is:
s.^[0:11] * x
and you could check all the values with a for loop:
for s = [0:11]
s.^[0:11] * x
end
Bill
---------- Original Message ----------------------------------
From: "John B. Thoo" <address@hidden>
Date: Fri, 27 Dec 2002 13:40:50 -0800
>Hi. I'm very new to using Octave. I have two questions: 1. What am I
>doing wrong in the following? 2. How can I do it more elegantly?
>
>
>I want to solve the system Ax = T where A is the 12x12 Vandermonde
>matrix
>
> [ 1 0 0 ... 0 ]
> [ 1 1 1 ... 1 ]
> A = [ 1 2 2^2 ... 2^11 ]
> [ ... ]
> [ 1 11 11^2 ... 11^11 ]
>
>
> T = [ 22 28 31 39 46 53 56 55 49 42 33 27 ]'
>
>To do this, I enter in Octave:
>
>octave:51> A = fliplr(vander([0,1,2,3,4,5,6,7,8,9,10,11]));
>octave:52> T = [22;28;31;39;46;53;56;55;49;42;33;27];
>octave:53> A\T
>ans =
>
> 2.2000e+01
> 1.2932e+02
> -3.3001e+02
> 3.5674e+02
> -2.1174e+02
> 7.7512e+01
> -1.8446e+01
> 2.9092e+00
> -3.0191e-01
> 1.9818e-02
> -7.4570e-04
> 1.2250e-05
>
>*But* when I go to check my answers, they seem to be off. To check my
>answers, I enter in Octave:
>
>octave:54> s = 0;
>octave:55> 22 + 129.32*s - 330.01*s**2 + 356.74*s**3 - 211.74*s**4 +
>77.512*s**5 - 18.446*s**6 + 2.9092*s**7 - 0.30191*s**8 + 0.019818*s**9 -
>0.0007457*s**10 + 0.00001225*s**11
>ans = 22
>octave:56> s = 1;
>octave:57> 22 + 129.32*s - 330.01*s**2 + 356.74*s**3 - 211.74*s**4 +
>77.512*s**5 - 18.446*s**6 + 2.9092*s**7 - 0.30191*s**8 + 0.019818*s**9 -
>0.0007457*s**10 + 0.00001225*s**11
>ans = 28.002
>octave:58> s = 3;
>
>and so on. The answers match well for the first few, but then they
>drift. To summarize, I get
>
> s | answers from Octave | supposed to be (T)
> ---------------------------------------------------
> 0 | 22 | 22
> 1 | 28.002 | 28
> 2 | 31.017 | 31
> 3 | 38.996 | 39
> 4 | 45.498 | 46
> 5 | 50.205 | 53
> 6 | 46.456 | 56
> 7 | 30.029 | 55
> 8 | - 5.5781 | 49
> 9 | -62.227 | 42
> 10 | -145.80 | 33
> 11 | -245.29 | 27
>
>
>TIA for your help.
>
>---John.
>
>
>
>-------------------------------------------------------------
>Octave is freely available under the terms of the GNU GPL.
>
>Octave's home on the web: http://www.octave.org
>How to fund new projects: http://www.octave.org/funding.html
>Subscription information: http://www.octave.org/archive.html
>-------------------------------------------------------------
>
>
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------