bugGNU Octave - Bugs: bug #60816, In a user created function if i...

 
 

bug #60816: In a user created function if i pass a vector it is incorrectly evaluated

Submitter:  None
Submitted:  Thu 24 Jun 2021 02:59:22 AM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Invalid / Not an Octave Bug Assigned to:  None
Originator Name:  Rosa MarĂ­a Valdespino Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 4.2.2
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 24 Jun 2021 03:33:30 AM UTC, comment #2: 

Dmitris explanation should help to debug the function.  If further assistance with debugging is needed, please visit Octaves user forum https://octave.discourse.group/c/help/6.

Closing this item.

Kai Torben Ohlhus <siko1056>
Group Member
Thu 24 Jun 2021 03:14:26 AM UTC, comment #1: 

if (x<=3) is not what you think it is.

From "help if":
<<<
The conditional COND is true if it is not empty and if all values are nonzero.

>>>



octave:9> x = linspace(0, 6, 9)
x =

 Columns 1 through 8:

        0   0.7500   1.5000   2.2500   3.0000   3.7500   4.5000   5.2500

 Column 9:

   6.0000

octave:10> x<=3
ans =

  1  1  1  1  1  0  0  0  0


so if(x<=3) goes to the "else" branch for this x vector.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Thu 24 Jun 2021 02:59:22 AM UTC, original submission:  


>> function y = momen(x)

if (x <= 3)
y = 75 .* x .- 20 .* x .**2 ./ 2 ;
else
y = 75 .* x .- 20 .* x .** 2 ./2 .- 30 .* (x .- 3);
endif
endfunction

x = linspace(0, 6, 9);

>> x

x =

   0.00000   0.75000   1.50000   2.25000   3.00000   3.75000   4.50000   5.25000   6.00000

>> z = momen(x);
>> z

z =

 Columns 1 through 7:

    90.00000   118.12500   135.00000   140.62500   135.00000   118.12500    90.00000

 Columns 8 and 9:

    50.62500     0.00000

<z = momen(x) >===> This is incorrect/>

>> momen(0), momen(0.75), momen(1.5), momen(2.25), momen(3), momen(3.75), momen(4.5), momen(5.25), momen(6)

ans = 0
ans =  50.625
ans =  90
ans =  118.12
ans =  135
ans =  118.12
ans =  90
ans =  50.625
ans = 0

>> < by "hand" momen(i) is correct />


Other data
GNU Octave, version 4.2.2

Processor intel(R) Celeron(R) M CPU 4730 @ 1.73 GHz (32 bits)

Kernel linux 4.15.0-122-generic(i686)
Ubuntu Mate 16.04.06

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by siko1056 (Posted a comment)
  • -email is unavailable- added by dasergatskov (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-06-24 siko1056 CategoryNone Interpreter
        StatusNone Invalid / Not an Octave Bug
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code