MATLAB: Product of a series multiplicationprod Hi, how should I write this production in matlab? p(k)=(m1−m2)*(m2−m3)*,…*,(mN−2−mN−1)*(m99−m100), where k from 1 to 100. thx Best Answer Numerically: m = rand(1, 100);m = rand(1, 100); % Row Vectorrm = reshape(m, 2, []);p = prod(diff(rm,[],1)) % Desired ResultEDIT — (21 Dec 2019 at 15:46)Alternatively: p = prod(-diff(rm,[],1)) % Desired Resultin the event that the first row was supposed to be subtracted from the second, instead of the second being subtracted from the first. Related SolutionsMATLAB: Simplify expression after collect function call vpa() on the expression. MATLAB: Plot system of ODE in 22 variables. The spaces in the individual rows are most likely causing the problem, for example in:...; (k1*x(2)*x(1)-r1*x(3))- 2*(k2*x(3)*x(3)-r2*x(4)); ...Either eliminate them:...; (k1*x(2)*x(1)-r1*x(3))-2*(k2*x(3)*x(3)-r2*x(4)); ...or put the entire row in parentheses so that MATLAB considers this one expression:...; ( (k1*x(2)*x(1)-r1*x(3))- 2*(k2*x(3)*x(3)-r2*x(4)) ); ...That should work, at least to eliminate that error.I cannot run your code. Related QuestionTextscan reading via row by row, can it read column by columnResize a matrix into another with different sizeSpeeding up 2D Finite Difference MatrixReplicate and rotate in 4D
Best Answer