leasqr function - global variables

German Ocampo gerocampo at gmail.com
Mon Jun 1 03:45:36 CDT 2009


Good morning

I'm new working with Octave and I have a question regarding to pass a
variable (dx) inside the objective function of the leasqr function. I define
the variable as global but Octave is giving me errors about this variable is
not defined inside the function.

How can I pass this variable? I'm including the code.

Thanks

German

function viblin
  % test data
  #data =  [0  0  0  0  1  2   5   7  10  13   16  19  21  24  27  30  33
 35   38  41  43  46  48  49  49  49]';
  #t    =  [1 2  3  4  5  6   7   8   9  10   11  12  13  14  15  16  17  18
  19  20  21  22  23  24  25  26]';

  data=[ 1 2 5 7 10 13 16 19 21 24 27 30 33 35 38 41 43 46 48 49]';
  t =  [ 1 2 3 4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20]';
  pin = [3.5; .45];
  F = @vel11;
  global dx;
  dx=50;
  global verbose;
  verbose=1;
 [f1, p1, kvg1, iter1, corp1, covp1, covr1, stdresid1, Z1, r21] = leasqr (t,
data, pin, F);

function y = vel11(x,p)
for i=1:length(x)
if (x(i)<(p(1)/p(2)))
y(i)=0.5*p(2)*x(i)^2;
else
if (x(i)<(dx/p(1)))
y(i)=p(1)*x(i)-p(1)*p(1)/(2*p(2));
else
y(i)=(dx-p(1)^2/(2*p(2)))-0.5*p(2)*(x(i)-dx/p(1))*(x(i)-dx/p(1))+p(1)*(x(i)-dx/p(1));
endif
endif
endfor
y=y';
endfunction
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www-old.cae.wisc.edu/pipermail/help-octave/attachments/20090601/098965f5/attachment-0001.html 


More information about the Help-octave mailing list