[Top][All Lists]

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

Re: vectorize inline function

From: James Sherman Jr.
Subject: Re: vectorize inline function
Date: Sat, 2 Aug 2014 15:00:50 -0400

On Sat, Aug 2, 2014 at 12:48 PM, isotrex <address@hidden> wrote:
here's the error:

octave-3.6.4.exe:15> secant
Enter Function:x^2*cos(x)-1
error: isinf: not defined for inline function
error: evaluating argument list element number 1
error: evaluating argument list element number 1
error: called from:
D:\Software\Octave-3.6.4\share\octave\3.6.4\m\plot\private\__plt__.m at
 line 219, column 3
D:\Software\Octave-3.6.4\share\octave\3.6.4\m\plot\private\__plt__.m at
 line 99, column 17
error:   D:\Software\Octave-3.6.4\share\octave\3.6.4\m\plot\plot.m at line
column 9
error:   D:\Software\Octave-3.6.4\numericals\secant.m at line 11, column 2

here's my code:

function ret = secant()
        a = input('Enter Function:','s');
        f = inline(a);

        #x = t.^2.*cos(t)-1; #<--- this works. just commented it out to try between
the two.
        x = vectorize(f);       #<---- this code does not
        axis([-6 4 -15 15])
        title('Plot of f(x)=x^2*cos(x)-1')
        grid on

I maybe missing something here. I don't know what isinf error either and
according to the manual...
isinf (x) [Mapping Function]
Return a logical array which is true where the elements of x are are
infinite and false
where they are not. For example:
isinf ([13, Inf, NA, NaN])

Also, is there a comment block for octave. It seems %{ %} or #{ #} doesn't
work. I'm using Octave 3.6.4 by the way. Thanks for taking your time in
helping me.

View this message in context:
Sent from the Octave - General mailing list archive at

Help-octave mailing list

The problem is that there is a difference between:
x = t.^2.*cos(t)-1;
x = vectorize(f);

What happens with the first option (that you have commented out in the code), is that x is a vector calculated from the values in t.  In the second option, you have that x is a function not a vector.  The fact that you used "t" as your variable in the string "a" has no relation to the t vector that you declare later on.    Note that in the example from the previous email, to evaluate the inline function at particular values, you need to call it like a function, x([0 .5]). So, all you need to do fix your code is to replace:

The error you get comes from inside the plot function and has to do with passing a vector and a function into plot and not two vectors (which is what its expecting).

As far as I know, there is no symbol in Octave to comment out a block of code.

Hope this helps.

James Sherman

reply via email to

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