octave - After one call to myfun, new parametrization does not affect the result, which conforms to the first call -


i new octave although can expert matlab user. running octave on linux server (red hat) remotely through putty, windows machine.

i observing strange behavior in octave. call myfun(a) performs expected giving sought results. now, if run, say, myfun(b) b!=a, again myfun(a). clear -f not solve problem. need reboot octave change parameters.

what doing wrong?

thanks lot francesco

this code function mentioned:

function [a, v, obj, infos, iter] = mle_garch( p )      #{     % function estimates garch(1,1)  parameters     % assumed pass adjusted price level p     #}     global y = (diff(log(p))-mean(diff(log(p))))*100;     global h = zeros(size(y));     a0 = [var(y)*0.9; 0.8; 0.1];     [a, obj, infos, iter] = sqp(a0, @loglike_garch, [], @loglike_con, [], [], 1000);     v = sqrt(h * 260);  endfunction  function g = loglike_garch( )      global y h     n = length(y);     h(1) = var(y);     = 2 : n,         h(i) = a(1) + a(2) * h(i-1) + a(3) * y(i-1)^2;     endfor     g = 0.5 * ( sum(log(h)) + sum(y.^2./h) ) / n;  endfunction  function f = loglike_con( )      f = [1;0;0;0] + [0 -1 -1;eye(3)] * a;  endfunction 

i'm assuming myfun mentioned mle_garch. problem way you're initializing global h , v variables (do need them global?). when have piece of code this

global y = (diff(log(p))-mean(diff(log(p))))*100; global h = zeros(size(y)); 

the values of y , h defined first time only. can change values later on, specific lines never ran again. since code uses input argument define these 2 variables, value use run function first time used every single other time. if want keep variables global, replace following:

global y; global h; y = (diff(log(p))-mean(diff(log(p))))*100; h = zeros(size(y)); 

but don't see reason keep them global don't make them global.

also, mentioned code worked fine in matlab. under impression couldn't initialize global , persistent variables in matlab make code illegal in matlab.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

mysql - Pass value between different pages (form) with PHP -