% MT 03 2018/19 % Challenge: Find the error in this code! fprintf ( ' Create a -1, 2, -1 tridiagonal matrix.\n ' ); fprintf ( ' Compare with the MATLAB online reference for "if, elseif, else". Find the error. \n ' ); m = 4; n = 6; a = zeros ( m, n ); % Expected result: % 2 -1 0 0 0 0 % -1 2 -1 0 0 0 % 0 -1 2 -1 0 0 % 0 0 -1 2 -1 0 for i = 1 : m for j = 1 : n value = 0.0; if ( j == (i - 1) || j == (i + 1) ) value = - 1.0; elseif ( j == i ) % Wrong Syntax here opens a new if-block!!! value = 2.0; else value = 0.0; end a(i,j) = value; end end a return % leaves if-block too early! %end Unneccesary