From help-octave-request at bevo dot che dot wisc dot edu Fri Dec 27 18:56:24 2002 Subject: Re: Newbie question solving lin sys From: "John B. Thoo" To: Cc: Date: Fri, 27 Dec 2002 16:55:47 -0800 On Friday, December 27, 2002, at 03:51 PM, William Lash wrote: >> **Three follow-up questions. (I hope that you don't mind.) >> >> 1. What does the dot after the s in s.^[0:11] mean in the "for" >> loop? > > In Octave (and Matlab), usually things like multiplication and > exponentiation are matrix type operations. Putting a "." in front > of the operation makes it do things in an "element by element" > fashion. To be honest, I wasn't sure that s.^[0:11] would give me > a row vector with the elements s^0 through s^11 untill I tried > it. I see. Neat. >> 2. What in the "for" loop tells Octave to add the terms? > > The multiplication of the row vector containing the powers of s > and the column vector containing the values of x in matrix > arithmetic give you the sum of the products as above. Think of > it as S*X where S is 1x12, and X is 12x1. You could do the same > using: > sum(x'.*s.^[0:11]) Oh, right, Octave treats everything as vectors. (I've played a little bit with Maple in the past; this is different here.) Duh! >> 3. How do I plot the graph on [0:11] without a loss of precision? I >> tried this without success: >> >> octave:84> gplot [0:11] "x(1) + x(2)*x + x(3)*x**2 + x(4)*x**3 + >> x(5)*x**4 + x(6)*x**5 + x(7)*x**6 + x(8)*x**7 + x(9)*x**8 + >> x(10)*x**9 + >> x(11)*x**10 + x(12)*x**11" >> line 0: undefined function: x > > I would probably do something like: > for s = [0:11] > z(s+1) = s.^[0:11] * x; > end > plot([0:11],z) 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. ---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 -------------------------------------------------------------