I solved this question with an if condition and the size of my solution was 39. I found the size of the leading solution to be 14. This is the leading solution: function ans = in_prod(x,y)
"no";
try
x*y;
end
How is this even correct? I tried to paste the same solution instead of mine and the assertion failed. z is not mentioned anywhere in this code. Can someone enlighten me?
If the output x*y is not assigned to any variable, MATLAB assigns it to the variable ans by default. In this solution, z has been replaced with ans in the function definition to return the unassigned output.
I am confused... this ought to work:
function z = in_prod(x,y)
if size(x,2) == size(y,1)
z = x * y
else
z = "The inner dimensions are " + size(x) + " and " + size(y) + ". Matrix multiplication is not possible"
end
This is dot product, not inner product, as the title suggests. They are not exactly the same.
I personally suggest substituting the title with 'dot product', as the description states.
What is wrong with this code? It's working on the downloaded version.
[xrow,xcol]=size(x);
[yrow,ycol]=size(y);
if xcol==yrow
z = x*y
else
z='Have you checked the inner dimensions?'
end
this problem is a little tricky. you have to output the exactly string mentioned in the problem description, not a random string.
function z = in_prod(x,y)
if length(x(1,:)) == length(y(:,1))
z = x*y;
else
z = "Have you checked the inner dimensions?"
end
end
function z = in_prod(x,y)
if length(x(1,:))==length(y(:,1))
z=x*y;
else
z="Have you checked the inner dimensions?"
end
end
function z = in_prod(x,y)
if size(x,2)==size(y,1)
z=x*y
else
z = "The inner dimensions are " + size(x,2) + " and " + size(y,1) + ". Matrix multiplication is not possible";
end
end
if size(x,2)==size(y,1)
z=x*y
else
z = "The inner dimensions are 3 and 2. Matrix multiplication is not possible"
end
Please, this code is working on Matlab but it did not work here , I think no problem with it
if size(x,2)==size(y,1)
z=x*y;
else
z = ['The inner dimensions are ', num2str(size(x,2)) ,' and ' ,num2str(size(y,1)), ' Matrix multiplication is not possible'];
end
display(z)
Please, this code is working on Matlab command widows, but in this problems it appears not correct, what is the problem please?
大佬强
Very interesting and logical solution to the problem.
233，666
Select every other element of a vector
22851 Solvers
How to find the position of an element in a vector without using the find function
2519 Solvers
870 Solvers
402 Solvers
3827 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!