Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

** Community Tip** - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements.
X

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Apr 25, 2020
03:45 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Apr 25, 2020
03:45 AM

Matric

Dear all

how to make multiple element by element and result as matrix? (Function As(DB,n,i)

Thank you

Solved! Go to Solution.

Labels:

1 ACCEPTED SOLUTION

Accepted Solutions

Apr 25, 2020
11:16 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Apr 25, 2020
11:16 AM

Here is an attempt from what I understood so far.

Vectorization as suggested by Terry sure is the clue, but its not so straightforward as you may think because we don't want to vectorize the elements of DB or n but just the elements of the results of the function n.s1() and A.sDB().

Here is one possible way to do it:

Additional remark: Its not necessary to vectorize the call A.sDB(DB) because the function uses DB^2 and squaring a vector is not defined in mathematics. So Prime automatically applies vectorization.

But in my opinion its good habit to apply the vectorization explicitly yourself in cases like this - just to be on the safe side in case you later change the function A.sDB.

10 REPLIES 10

Apr 25, 2020
04:24 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Apr 25, 2020
04:24 AM

Hi,

Try "vectorisation".

On the ribbon at Math | Operators - lower right hand corner.

Cheers

Terry

Apr 25, 2020
11:00 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Apr 25, 2020
11:00 AM

Please attach your worksheet.

And state clearly, what exactly you expect as desired result. For this it might be helpful if you change the input matrices DB and n in a way so not all entries are the same value.

Apr 25, 2020
11:16 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Apr 25, 2020
11:16 AM

Here is an attempt from what I understood so far.

Vectorization as suggested by Terry sure is the clue, but its not so straightforward as you may think because we don't want to vectorize the elements of DB or n but just the elements of the results of the function n.s1() and A.sDB().

Here is one possible way to do it:

Additional remark: Its not necessary to vectorize the call A.sDB(DB) because the function uses DB^2 and squaring a vector is not defined in mathematics. So Prime automatically applies vectorization.

But in my opinion its good habit to apply the vectorization explicitly yourself in cases like this - just to be on the safe side in case you later change the function A.sDB.

Apr 25, 2020
12:26 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Apr 25, 2020
12:26 PM

Now I am not near my pc. Yep that I prefer but when I enlarge matrix DB 1x4 or higher it will work ?

i will test tomorrow, I will be back

big thank Werner_E &Terry

Apr 25, 2020
01:33 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Apr 25, 2020
01:33 PM

@SPRstructur wrote:

...

when I enlarge matrix DB 1x4 or higher it will work ?

...

You will have to enlarge the matrix n, too.

As long as DB and n will have the same number of rows, it should work OK without any changes.

Apr 25, 2020
05:29 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Apr 25, 2020
05:29 PM

As I'm in a cat-skinning mood, here's another approach that uses functions to achieve the desired outcome.

Element-by-element multiplication is conventionally referred to as Hadamard (or Schur) multiplication. The attached worksheet implements it as the function *hadamard *and applies it to your problem. The worksheet also includes the *map*, *zeros,* *ones* and *seq* functions.

Here are the *hadamard *and *map *functions,

And here are the *zeros,* *ones* and *seq* functions.

Stuart

Apr 25, 2020
09:21 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Apr 25, 2020
09:21 PM

Always nice to see your thought son problems and your consequent use a (useful) custom functions.

There is no need for "i" anyway. Neither as range, nor as argument in function "A.s".

Apr 29, 2020
11:52 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Apr 29, 2020
11:52 AM

Vielen Dank, Werner. I'm pretty sure any one of a number of the "core" Mathcadders (yourself included) would have come up with a similar solution if you too came late to the party! 😎

Working with Prime Express somewhat forces a purer functional mindset. If I could find nice (ie, quick and short), non-programming ways to return an array after setting an element and to convert an n-parameter function into an n-1 parameter function, I'd be happy.

Well, I would be if the recursion depth wasn't so shallow, although that in itself is just one more challenge to work around. The lack of expression wrap-around is also a limiting factor as far as readability goes.

Sowieso zurück zur Geschichte, yes, I wondered about the 'i' and guessed it might have been intended for some future use when the OP got the function working.

Stuart

Apr 26, 2020
09:13 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Apr 26, 2020
09:13 AM

Nice, Stuart,

However there's no need to define the _one() and _zero() functions, see below:

Caution: With the 'min' function, you have to set the label of it to 'function'. Prime doesn't understand simple things...

Luc

Apr 29, 2020
09:48 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Apr 29, 2020
09:48 AM

@LucMeekes wrote:

Nice, Stuart,

However there's no need to define the _one() and _zero() functions, see below:

Caution: With the 'min' function, you have to set the label of it to 'function'. Prime doesn't understand simple things...

Luc

Hi, Luc.

Yes, I've been bitten a few times by forgetting that Prime treats **min** a bit differently.

The reason I use ** zero **and

The real nuisance is not being able to use partial application in Prime. What I'd have done (and did do) in M15 would be to write a function like* matseq(m,i,j) := i + m * j *and then define a function

Unfortunately, I can't think of a neat way of doing this in Prime Express (*it would be straightforward in Prime Premium, of course, by defining a local function matrix(m,n,l(i,j)<-matseq(m,i,j)*). The best I've been able to come up with is a double-

Anyway, enough rambling, here's a plot of the times for the two approaches to generating an all-ones matrix:

Stuart