[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 11:56:34 -0400

On Sat, Aug 2, 2014 at 1:40 AM, isotrex <address@hidden> wrote:
How do I vectorize an inline function?
I've already tried searching the web and it seem the vectorize inline
function has been deprecated.
What I want is when I input like x^2*cos(x)-1 it would change to a vectorize
format which is x.^2.*cos(x)-1.

Here's the code I got which doesn't work...

        a = input('Enter Function:','s');
        f = inline(a);
        x = vectorize(f);

Is there an alternative way so I can vectorize a given input function?
Any help or guide would be greatly appreciated.

Hi Kent,

A better way to help diagnose the problem is to give us a bit more detail about what happens when it "doesn't work".  Particularly the output and error message of an example where things don't happen the way you expect them too.  My first guess is that something is going wrong because you renamed your vectorized function as "x" where (and again this is just a guess) your data/input is also named "x".  The following worked for me (though this is only in octave 3.6.0)

octave:12> a = input('Enter Function', 's')
Enter Functionx^2*cos(x)
a = x^2*cos(x)
octave:13> f = inline(a)
f = f(x) = x^2*cos(x)
octave:14> x = vectorize(f)
x = f(x) = x.^2.*cos(x)
octave:15> x([0 .5])
ans =

   0.00000   0.21940

Hope this helps,

James Sherman

reply via email to

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