HP Forums
Apply a function to a vector - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Apply a function to a vector (/thread-5736.html)

Apply a function to a vector - Maro - 02-22-2016 11:10 AM

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!

RE: Apply a function to a vector - DrD - 02-22-2016 11:28 AM

Perhaps, something like this?



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


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


RE: Apply a function to a vector - Maro - 02-22-2016 12:31 PM

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

RE: Apply a function to a vector - cyrille de brébisson - 02-23-2016 07:10 AM


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.