Apply a function to a vector
02-22-2016, 11:10 AM
Post: #1
 Maro Member Posts: 67 Joined: May 2014
Apply a function to a vector
I would like to apply an arbitrary function to a predefined vector in HOME environment or in a program for some numerical analysis, similar to Matlab.
For example in Matlab I define a vector of discrete time values and apply a function to this vector simply by two commands:

t = (0:0.001:1); ➝ time vector from 0 to 1 sec with 1001 samples
y = sin(t); ➝ y is a vector with 1001 sampled sin(t) - values

Is that also possible with the prime in Home or in programs? I think the CAS functions "apply" or "map" can do this job, but I would like to avoid using CAS functions for the numerical analyses I'm working on.

Thanks for any input!
Maro
02-22-2016, 11:28 AM (This post was last modified: 02-22-2016 12:07 PM by DrD.)
Post: #2
 DrD Senior Member Posts: 1,132 Joined: Feb 2014
RE: Apply a function to a vector
Perhaps, something like this?

t:=MAKELIST(X,X,0,1,0.001);
y:=SIN(t);

-or-

y:=SIN(MAKELIST(X,X,0,1,0.001)); // y:=sin(X)

-or-

M1:=SIN(t); // Uses reserved variable M1 to save in matrix (vector) form.

-Dale-
02-22-2016, 12:31 PM
Post: #3
 Maro Member Posts: 67 Joined: May 2014
RE: Apply a function to a vector
Great! Thanks a lot, Dale. That works doing it with MAKELIST.
I didn't think about lists and only noticed that functions like SIN don't accept vectors as arguments. When using a list as argument it works fine.

Thanks again
Maro
02-23-2016, 07:10 AM
Post: #4
 cyrille de brébisson Senior Member Posts: 1,009 Joined: Dec 2013
RE: Apply a function to a vector
Hello,

Mathlab does not have a distinction between lists and vectors/matrices.

Prime does as they are different mathematical objects and behave differently with regard to some mathematical operations. Therefore the difference.

Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)