The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function

 How to obtain element-wise squaring of vector/matrix?
11-26-2019, 07:40 PM
Post: #1
 mbeddo Member Posts: 54 Joined: Nov 2014
How to obtain element-wise squaring of vector/matrix?
I'm implementing a non-linear fitting routine and [/code]I need to square the elements of a vector from within a program. From the CAS screen I can easily square the elements of a vector [1, 2, 3, 4]:

The simple program below has a syntax error:

Code:
 EXPORT DEMO() BEGIN   LOCAL myvec;   myvec := [1, 2, 3, 4];   apply(x→x^2, myvec); END;

I don't know what I'm doing wrong.

I looked for a function that would square element-wise, and "apply" seemed to fit the bill. I'm trying to avoid a FOR loop.

I think it would be easier if I just squared a list of numbers, then converted the answer to a vector?
 « Next Oldest | Next Newest »

 Messages In This Thread How to obtain element-wise squaring of vector/matrix? - mbeddo - 11-26-2019 07:40 PM RE: How to obtain element-wise squaring of vector/matrix? - swagner53 - 11-26-2019, 08:47 PM RE: How to obtain element-wise squaring of vector/matrix? - mbeddo - 11-27-2019, 07:16 AM RE: How to obtain element-wise squaring of vector/matrix? - goetz - 11-26-2019, 11:18 PM RE: How to obtain element-wise squaring of vector/matrix? - mbeddo - 11-27-2019, 07:20 AM

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