Cody

Problem 44740. New Matrix with vector addition on diagonal

Solution 1659253

Submitted on 25 Oct 2018 by goc3
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
x=[1 2 3]; y=[4 5 6]; z_correct = [5 6 7;6 7 8;7 8 9] assert(isequal(addmat(x,y),z_correct))

z_correct = 5 6 7 6 7 8 7 8 9 ans = 5 6 7 6 7 8 7 8 9

2   Pass
x=[10 20 30 40]; y=[-10 -20 -30 -40]; z_correct = [0 10 20 30;-10 0 10 20;-20 -10 0 10;-30 -20 -10 0] assert(isequal(addmat(x,y),z_correct))

z_correct = 0 10 20 30 -10 0 10 20 -20 -10 0 10 -30 -20 -10 0 ans = 0 10 20 30 -10 0 10 20 -20 -10 0 10 -30 -20 -10 0

Suggested Problems

More from this Author4

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!