help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Getting complex numbers results instead of expected real numbers


From: ant
Subject: Getting complex numbers results instead of expected real numbers
Date: Sun, 12 Feb 2012 06:19:43 -0800 (PST)

When running a script in Octave 3.4.3, I'm getting complex numbers of the
form (a+0.0000i) or (a-0.0000i), instead of the expected real number a. Any
help will be much appreciated!

OUTPUT:
************************************************************
octave:0>info_test
octave:1> info_vec =

    20.0000 +   0.0000i     9.6388 +   0.0000i
    30.0000 +   0.0000i    10.3678 -   0.0000i
    40.0000 +   0.0000i    11.2201 +   0.0000i
    50.0000 +   0.0000i    12.1703 +   0.0000i
    60.0000 +   0.0000i    13.2062 +   0.0000i
    70.0000 +   0.0000i    14.3192 -   0.0000i
    80.0000 +   0.0000i    15.5026 -   0.0000i
    90.0000 +   0.0000i    16.7513 -   0.0000i
   100.0000 +   0.0000i    18.0610 +   0.0000i
   110.0000 +   0.0000i    19.4281 +   0.0000i
   120.0000 +   0.0000i    20.8496 -   0.0000i
   130.0000 +   0.0000i    22.3228 -   0.0000i
   140.0000 +   0.0000i    23.8454 -   0.0000i
   150.0000 +   0.0000i    25.4154 +   0.0000i
   160.0000 +   0.0000i    27.0310 -   0.0000i
   170.0000 +   0.0000i    28.6904 +   0.0000i
   180.0000 +   0.0000i    30.3922 +   0.0000i
   190.0000 +   0.0000i    32.1350 -   0.0000i
   200.0000 +   0.0000i    33.9176 -   0.0000i
   210.0000 +   0.0000i    35.7389 -   0.0000i
   220.0000 +   0.0000i    37.5977 -   0.0000i

SCRIPT:
*****************************************************
global sigma r mu k0 alpha beta delta gama phistar c0
global l1p l1m l2p l2m

sigma = 0.10; mu = -0.02; r = 0.10;
l1p = -mu/sigma^2 -1/2 + sqrt((mu/sigma^2+1/2)^2+(2*(r-mu)/sigma^2));
l1m = -mu/sigma^2 -1/2 - sqrt((mu/sigma^2+1/2)^2+(2*(r-mu)/sigma^2));
l2p = -mu/sigma^2 +1/2 + sqrt((mu/sigma^2-1/2)^2+(2*r/sigma^2));
l2m = -mu/sigma^2 +1/2 - sqrt((mu/sigma^2-1/2)^2+(2*r/sigma^2));

gama = 10; phistar=0.6; alpha = 0.7; beta = 1/7.36936815669474; delta =
0.20;
c0_iter = linspace(20,220,21);

info_vec = [];
for c0 = c0_iter
    k0 = (beta*c0)^(1/alpha);
    function y1 = ClosureTrigger(xtau)
        global r mu sigma c0 gama alpha beta k0 phistar delta l1p l1m l2p
l2m
        y1 =
l2m*(r-mu)*(l1p-l1m)*(phistar*k0+(gama+delta*k0)/r-c0/r*(xtau/c0)^l2p)-((l2m-1)*(l1p-l1m)-l1m*(1+l1p-l2m)*(xtau/c0)^l1p)*xtau;
    endfunction
    function y2 = OptimalClosure()
        [y2] = fsolve(@ClosureTrigger,0);
    endfunction
    xstar = OptimalClosure();
    info_vec = [info_vec; c0 xstar];
endfor
info_vec


--
View this message in context: 
http://octave.1599824.n4.nabble.com/Getting-complex-numbers-results-instead-of-expected-real-numbers-tp4381221p4381221.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]