bugGNU Octave - Bugs: bug #37168, Different results using feval with...

 
 

bug #37168: Different results using feval with the same function with and without linspace

Submitter:  None
Submitted:  Wed 22 Aug 2012 04:10:39 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Invalid / Not an Octave Bug Assigned to:  None
Originator Name:  EDM Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 3.6.2
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 22 Aug 2012 04:30:41 PM UTC, comment #2: 

I don't think the formula you wrote is doing what you think it is.

You either need some additional parentheses to override default precedence rules, or you need to use .* and ./.  I'm not sure what you intend, so I don't know what is correct.  But as it is, you are doing some matrix operations when you pass a vector in for X, not a series of scalar operations.

John W. Eaton <jwe>
Group administrator
Wed 22 Aug 2012 04:29:51 PM UTC, comment #1: 

"Is anything wrong with my code?"

Yes, your inline function is not correctly vectorized,
you should have written it as:


dg1=inline('0.5.*(log(x.^2+2)).^(-0.5).*(2.*x./(x.^2+2))')


the function 'vectorize' may be of help in avoiding similar mistakes:


>> vectorize ('0.5*(log(x.^2+2)).^(-0.5)*(2*x/(x.^2+2))')
ans = 0.5.*(log(x.^2+2)).^(-0.5).*(2.*x./(x.^2+2))
>>


Please, in the future, use the help mailing list rather than this bug tracker if you have questions about using Octave.

c.


Carlo de Falco <cdf>
Group Member
Wed 22 Aug 2012 04:10:39 PM UTC, original submission:  

Hi,
I was using octave in Arch Linux with this code:


dg1=inline('0.5*(log(x.^2+2)).^(-0.5)*(2*x/(x.^2+2))');
feval(dg1,0.5)
feval(dg1,1.5)
xx1=linspace(0.5, 1.5);
feval(dg1,xx1)


The output of the first two feval is different from the output given from the last feval using linspace.


feval(dg1,1.5)
ans =  0.29341


but

feval(dg1,xx1)
(...)
0.27436


Is anything wrong with my code?

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 jwe (Posted a comment)
  • -email is unavailable- added by cdf (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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-08-22 jwe Item GroupNone Incorrect Result
    2012-08-22 cdf Item GroupIncorrect Result None
        StatusNone Invalid / Not an Octave Bug
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-bb6a.
    Corresponding source code