Problem 44950. Calculate Inner Product
Given two input matrices, x and y, check if their inner dimensions match.
- If they match, create an output variable z which contains the product of x and y
- Otherwise, z should contain a custom string message
Example:
x = [1 2;3 4]
y = [5;6]
z = [17;39]
x = [1 2 3;4 5 6]
y = [2 5;3 6]
z = "Have you checked the inner dimensions?"
OR
z = "The inner dimensions are 3 and 2. Matrix multiplication is not possible"
-------------------------------------------------------------------------------------------------------------------------------------------------------------
NOTE - An example of combining numbers and strings together is shown below:
x = "The sum of " + 4 + " and " + 3 + " equals " + 7
x =
"The sum of 4 and 3 equals 7"
Solution Stats
Problem Comments
-
11 Comments
Show
8 older comments
Farooq
on 15 Sep 2022
DO NOT use disp when printing the string for z, just use z = "string message". Otherwise even if your code is correct it will not complete the problem.
MOHAMMED ARSHAD S
on 10 Jan 2024
Why adding z=[]; after z="Have you....?" is failing in Test case?
Dengqian
on 17 Jul 2024
This is grossly misleading for aspiring linear algebra students. The product calculated in this example is called a "matrix multiplication product", not a "inner product". The "inner product" is a generalization of the dot product.
Solution Comments
Show commentsGroup

Project Euler II
- 12 Problems
- 51 Finishers
- Sums of cubes and squares of sums
- Sum of big primes without primes
- Project Euler: Problem 11, Largest product in a grid
- Highly divisible triangular number (inspired by Project Euler 12)
- Divisors for big integer
- Large Sum (inspired by Project Euler 13)
- Longest Collatz Sequence
- Project Euler: Problem 16, Sums of Digits of Powers of Two
- Project Euler: Problem 18, Maximum path sum I
- Recurring Cycle Length (Inspired by Project Euler Problem 26)
- Numbers spiral diagonals (Part 1)
- Numbers spiral diagonals (Part 2)
Problem Recent Solvers7506
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!