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

High School Challenge
- 50 Problems
- 98 Finishers
- Times 2 - START HERE
- Add two numbers
- Laws of motion 3
- Laws of motion 6
- Force and Motion 2
- Force and Motion 3
- Velocity Conversion
- Potential energy calculation
- An Ohm's Law Calculator
- Electrical Diode Current Calculation
- Resistance of a light bulb
- Calculate Parallel Resistance
- Current through resistor
- Energy Conversion 2
- Mass Conversion 1
- Convert from Fahrenheit to Celsius
- Return area of square
- Area Conversion 1
- Create times-tables
- Triangle Numbers
- How long do each of the stages of the rocket take to burn?
- Finding Perfect Squares
- Magnitude of Balancing Force
- Mechanical Advantage of a Gear Train
- Calculate load on arm 1
- Find the mass of a rod
- Find the force required to support a lever
- Coefficient of Kinetic friction
- Calculate the acceleration of a crate
- Coefficient of Sliding Friction
- Coefficient of Static friction
- Linear Motion 1
- Linear Motion 2
- Linear Motion 3
- Linear Motion 4
- Linear Motion 5
- Linear Motion 6
- Linear Motion 7
- Basic Mathematics 1
- Basic Mathematics 2
- Basic Mathematics 3
- Basic Mathematics 4
- Basic Mathematics 5
- Basic Mathematics 6
- Basic Mathematics 7
- Basic Mathematics 8
- Resistance of a robot
- Voltage in a lamp
- Resistance in a circuit
- Calculate supply voltage and total current
Problem Recent Solvers7503
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!