How to resolve the algorithm Element-wise operations step by step in the Mathematica / Wolfram Language programming language

Published on 4 July 2024 02:40 AM

How to resolve the algorithm Element-wise operations step by step in the Mathematica / Wolfram Language programming language

Table of Contents

Problem Statement

This task is similar to:

Implement basic element-wise matrix-matrix and scalar-matrix operations, which can be referred to in other, higher-order tasks. Implement:

Extend the task if necessary to include additional basic operations, which should not require their own specialised task.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Element-wise operations step by step in the Mathematica / Wolfram Language programming language

The Wolfram code you provided performs various element-wise operations on two matrices, M and S, and prints the results. Let's break down each operation and its output:

  1. M + S: Adds the scalar value S to each element of matrix M.

    • Output: {{17, 21, 23}, {27, 29, 33}, {39, 41, 47}}
  2. M - S: Subtracts the scalar value S from each element of matrix M.

    • Output: {{-3, 1, 3}, {7, 9, 13}, {19, 21, 27}}
  3. M * S: Multiplies each element of matrix M by the scalar value S.

    • Output: {{70, 110, 130}, {170, 190, 230}, {290, 310, 370}}
  4. M / S: Divides each element of matrix M by the scalar value S.

    • Output: {{7/10, 11/10, 13/10}, {17/10, 19/10, 23/10}, {29/10, 31/10, 37/10}}
  5. M ^ S: Raises each element of matrix M to the power of S.

    • Output: {{282475249, 25937424601, 137858491849}, {2015993900449, 6131066257801, 41426511213649}, {420707233300201, 819628286980801, 4808584372417849}}
  6. M + M: Adds the matrices M element-wise.

    • Output: {{14, 22, 26}, {34, 38, 46}, {58, 62, 74}}
  7. M - M: Subtracts matrix M from itself element-wise.

    • Output: {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}
  8. M * M: Multiplies matrices M element-wise.

    • Output: {{49, 121, 169}, {289, 361, 529}, {841, 961, 1369}}
  9. M / M: Divides matrix M by itself element-wise.

    • Output: {{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}
  10. M ^ M: Raises matrix M to the power of itself element-wise.

    • Output: {{823543, 285311670611, 302875106592253}, {827240261886336764177, 1978419655660313589123979, 20880467999847912034355032910567}, {2567686153161211134561828214731016126483469, 17069174130723235958610643029059314756044734431, 10555134955777783414078330085995832946127396083370199442517}}

Source code in the wolfram programming language

S = 10 ; M = {{7, 11, 13}, {17 , 19, 23} , {29, 31, 37}};
M + S
M - S
M * S
M / S
M ^ S

M + M
M - M
M * M
M / M
M ^ M

Gives:

->{{17, 21, 23}, {27, 29, 33}, {39, 41, 47}}
->{{-3, 1, 3}, {7, 9, 13}, {19, 21, 27}}
->{{70, 110, 130}, {170, 190, 230}, {290, 310, 370}}
->{{7/10, 11/10, 13/10}, {17/10, 19/10, 23/10}, {29/10, 31/10, 37/10}}
->{{282475249, 25937424601, 137858491849}, {2015993900449, 
  6131066257801, 41426511213649}, {420707233300201, 819628286980801, 
  4808584372417849}}

->{{14, 22, 26}, {34, 38, 46}, {58, 62, 74}}
->{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}
->{{49, 121, 169}, {289, 361, 529}, {841, 961, 1369}}
->{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}
->{{823543, 285311670611, 302875106592253}, {827240261886336764177, 
  1978419655660313589123979, 
  20880467999847912034355032910567}, {2567686153161211134561828214731016126483469, 
  17069174130723235958610643029059314756044734431, 
  10555134955777783414078330085995832946127396083370199442517}}


  

You may also check:How to resolve the algorithm HTTPS step by step in the Ioke programming language
You may also check:How to resolve the algorithm Sorting Algorithms/Circle Sort step by step in the Swift programming language
You may also check:How to resolve the algorithm Reverse a string step by step in the NS-HUBASIC programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the Clipper programming language
You may also check:How to resolve the algorithm Create a file step by step in the PicoLisp programming language