help-octave
[Top][All Lists]

## Re: Newbie question solving lin sys

 From: John W. Eaton Subject: Re: Newbie question solving lin sys Date: Fri, 27 Dec 2002 19:58:34 -0600

```On 27-Dec-2002, John B. Thoo <address@hidden> wrote:

| That works to give me a polygonal curve that connects the 12 points.
| That's good, but how would I plot the polynomial with more grid points
| (smoother)?  It works reasonably when I do "format long" and then copy &
| paste the coefficients to plot
|
| octave:139> gplot [0:11] "22 + 129.316052352359*x -
| 330.008191451222*x**2 + 356.743251568416*x**3 - 211.743557625161*x**4 +
| 77.5116682813202*x**5 - 18.4455900615644*x**6 + 2.90919225949428*x**7 -
| 0.301909718420775*x**8 + 0.0198178458639753*x**9 -
| 0.000745701048375786*x**10 + 0.0000122504808365439*x**11"
|
| but there must be an easier way. :-)
|
| Once again, thanks very much for all your help.

In Octave, a polynomial is represented by its coefficients (arranged
in descending order).  For example, a vector C of length N:

p(x) = C(1) x^N + ... + C(N) x + C(N+1).

Try something like

A = [...];
T = [...];
c = flipud (A\T);  ## note that you ended up with coefficients in
## the opposite order from what Octave's poly
## functions want...
x = 0:0.1:11;
y = polyval (c, x)
plot (x, y);

Makes a nice plot for me given your original A and T.

jwe

-------------------------------------------------------------
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
-------------------------------------------------------------

```