Mercurial > forge
changeset 964:692f4de142f8 octave-forge
(Rolf Fabian) Handle complex-valued x,y.
author | pkienzle |
---|---|
date | Fri, 06 Jun 2003 18:30:50 +0000 |
parents | 1068520a820d |
children | 15ebecf7c596 |
files | main/optim/wpolyfit.m |
diffstat | 1 files changed, 29 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/main/optim/wpolyfit.m Tue Jun 03 09:36:03 2003 +0000 +++ b/main/optim/wpolyfit.m Fri Jun 06 18:30:50 2003 +0000 @@ -159,6 +159,19 @@ if nargout == 0 + if iscomplex(p) + printf("%32s %15s\n", "Coefficient", "Error"); + printf("%15g %+15gi %15g\n",[real(p(:)),imag(p(:)),dp(:)]'); + # XXX FIXME XXX how to plot complex valued functions? + # Maybe using hue for phase and saturation for magnitude + # e.g., Frank Farris (Santa Cruz University) has this: + # http://www.maa.org/pubs/amm_complements/complex.html + # Could also look at the book + # Visual Complex Analysis by Tristan Needham, Oxford Univ. Press + # but for now we punt + return + endif + ## decorate the graph grid('on'); xlabel('abscissa X'), ylabel('data Y'), @@ -183,15 +196,28 @@ ## display p,dp as a two column vector printf("%15s %15s\n", "Coefficient", "Error"); - printf("%15f %15f\n", [p(:), dp(:)]'); + printf("%15g %15g\n", [p(:), dp(:)]'); else ## return values as row vectors instead of printing - p_out = p'; - if (compute_dp) dp_out = dp'; endif + p_out = p.'; + if (compute_dp) dp_out = dp.'; endif endif endfunction +%!demo % #1 +%! x = linspace(0,4,20); +%! dy = (1+rand(size(x)))/2; +%! y = polyval([2,3,1],x) + dy.*randn(size(x)); +%! wpolyfit(x,y,dy,2); + +%!demo % #2 +%! x = linspace(-i,+2i,20); +%! noise = ( randn(size(x)) + i*randn(size(x)) )/10; +%! P = [2-i,3,1+i]; +%! y = polyval(P,x) + noise; +%! [PEST,DELTA]=wpolyfit(x,y,2) +