Problem 135. Inner product of two vectors
Solution Stats
Problem Comments

10 Comments
I think it would be helpful if you specified whether the vectors are row vectors, column vectors, or whether they can be an arbitrary mixture. The test suite only has row vectors, but this makes it rather trivial.
If the x and y vectors could be row and column vectors, then bsxfun(@times, x, y) does a better job
Test set should include some column vectors.
if you make the examplefunction "y = fcn(x,y)
z = x*y", please make sure matlab at least handles it; "z = fcn(x,y)
z = x*y" would be preferred =)
This function already exists, look up the dot function
In the given code snippet, make some changes to correct the function definition. (The first line)
Tricky on the variable to return... not sure if it was for teaching howtodebug purposes.
funny, after all.
Remember to edit the return variable (change it from y to z)
LOOK FOR 'y' INLINE 1
CHANGE IT TO 'z'!!!!!!!!!!
love it
Solution Comments

1 Comment
tricky and conceptual

2 Comments
Was confused for a second, probably because the operation isnt usually called the inner product
It *is* called Inner Product

1 Comment
I didn't know what it meant by "inner product" and that's why I was confused.

1 Comment
Literally just pressing one key...

1 Comment
easy

2 Comments
simple question
Good problem

1 Comment
good problem

1 Comment
I would clarify inner product. I've never heard it called that before and had to Google.

1 Comment
good review

1 Comment
Considering, that solving a complete random sudoku was rated medium, this should be marked easy!!

1 Comment
tried differnt method,every time it showing 'Assertion failed.', my result is right every time. give me tips so i can solve this problem.

1 Comment
A oneline code... Smart question :) had forgotten about this command.

1 Comment
y = dot(x,y)

1 Comment
This example doesn't work, should be z = dot(x,y), or z = sum(x.*y)

1 Comment
Please correct this problem. The output is y when it should be z_correct.

1 Comment
is the problem is correct? do we take output y or z?

1 Comment
LOL @y set as the output. I was nearly convinced this problem was invalid.

1 Comment
change the output variable to be z

1 Comment
I'm a bit confused. The code outputs the correct answers for the test suite, but it seems I do not pass while submitting.

1 Comment
answer is in terms of z but function give answer in terms of y again confused and give error for simple problem

1 Comment
Nice little bug in there.

1 Comment
This user (mohamed elbesealy) appears to have gamed the system, with fraudulent "likes" of this unremarkable solution submitted by 'sockpuppet' accounts. —DIV

1 Comment
This is correct. What am I missing?

1 Comment
eazy eazy

3 Comments
Why is this smaller than just x*y'?
NOt just that, his output is y instead of z!! jajaj...
That is the matrix attribute!

1 Comment
i wrote solution like below
z = sum(x.*y);
it is working on my laptop but in cody show incorrect tell me why

3 Comments
Hmmm, description is a little confusing. Is length(x) always = length(y)? Are they nx1 or 1xn? Anyhow, I submitted several possible solutions (e.g. z = x'*y, z = sum(x.*y)) all of which failed the test suite ... but they work fine on my machine!
Note that the output variable in the pattern is y, not z.
ha, yeah. thanks for commenting about that. I didn't see it either.
Problem Recent Solvers6387
Suggested Problems

Find the largest value in the 3D matrix
1249 Solvers

Find nearest prime number less than input number
449 Solvers

Simple equation: Annual salary
4010 Solvers

605 Solvers

787 Solvers
More from this Author100
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!