bugGNU Octave - Bugs: bug #53220, Sending strings to quadl

 
 

bug #53220: Sending strings to quadl

Submitter:  None
Submitted:  Sat 24 Feb 2018 08:32:50 PM UTC
   
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Invalid / Not an Octave Bug Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 4.2.1
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 27 Feb 2018 03:56:30 PM UTC, comment #3: 

The quad error message is different because it can actually accept raw code to execute, rather than the documented first argument for all the other quad functions:


F is a function handle, inline function, or string containing the
name of the function to evaluate


For example,


quad ("x.^2 + 1", 0, 2)
warning: quad: passing function body as a string is obsolete; please use anonymous functions
ans =  1.3333


Try the same thing with quadl and you get


quadl ("x.^2 + 1", 0, 2)
error: feval: function 'x.^2 + 1' not found


because it recognizes that the double-quoted object is a string, and therefore should be the name of a function.

Accordingly, you can either give it a function handle, inline function, or name of a function that calculates what you want.


octave:5> function y = MYF (x)
> y = x.^2 + 1;
> endfunction
octave:6> quadl ("MYF", 0, 1)
ans =  1.3333
octave:7> quadl (@(x) x.^2 + 1, 0, 1)
ans =  1.3333
octave:8> quadl (inline ("x.^2 + 1"), 0, 1)
ans =  1.3333



Rik <rik5>
Group administrator
Tue 27 Feb 2018 04:08:22 AM UTC, comment #2: 

You also don't need to use


quadl (@(x) sin(x), 0, pi)


You can just use @sin:


quadl (@sin, 0, pi)


I suspect the error messages are different simply because these functions were written by different people who handled the function arguments differently.  If we fix that, it might be good to review all functions in Octave that call user-defined functions, agree on the best way to handle them, and make them all consistent.

John W. Eaton <jwe>
Group administrator
Mon 26 Feb 2018 05:52:49 PM UTC, comment #1: 

You can use just


quadl ("sin", 0, pi)
ans =  2.0000


The string in question is the name of the function, rather than actual code.  For example, if you had an m-file implementation named myfunc.m then you would call


quadl ("myfunc", 0, pi)


You couldn't use


quadl (myfunc, 0, pi)


because that would mean that you wanted to call myfunc and use the return value as the first argument to quadl.


Rik <rik5>
Group administrator
Sat 24 Feb 2018 08:32:50 PM UTC, original submission:  

Using quad


quad('sin(x)',0,pi)
warning: quad: passing function body as a string is obsolete; please use anonymous functions
ans =                    2


Using quadl


quadl('sin(x)',0,pi)
error: feval: function 'sin(x)' not found
error: called from
    quadl at line 89 column 5


Using quadl and a function

F2= @(x) sin(x);
>> quadl(F2,0,pi)
ans =                    2


The help section states I could use a string. I would anticipate the same warning as in quad if it is obsolete.

Am I misunderstanding the help section?

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 rik5 (Posted a comment)
  •  

    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 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-02-26 rik5 StatusNone Invalid / Not an Octave Bug
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code