MATLAB: Simple Question: gradient function Formula gradient formula in the following line, x is a 200 element column vector, h is a scalar eg.say 20 or 30 a = gradient(x,h) can you please tell how 'a' is computed from x and h? Thanks in advance Best Answer For 2 <= k <= 199, the computation is a central difference: a(k) = (x(k+1)-x(k-1))/(2*h)However, for the two endpoints it is: a(1) = (x(2)-x(1))/h a(200) = (x(200)-x(199))/hIn case h is a vector of the same length as x, then it becomes a divided difference: a(k) = (x(k+1)-x(k-1))/(h(k+1)-h(k-1))and a(1) = (x(2)-x(1))/(h(2)-h(1)) a(200) = (x(200)-x(199))/(h(200)-h(199)) Related SolutionsMATLAB: Function Intersection using Newton’s Method You're not updating h and dh within your loop. MATLAB: Pass a parameter to vector of variables for fmincon Probably the easiest way is to set ‘x0’ appropriately and then bound ‘x(2)’ to be 40:x0 = [20 40 20];lb = [0 40 0];ub = [100 40 100];fun = @(x) x(1)+x(2)+x(3);x_min = fmincon(fun,x0,[],[],[],[],lb,ub) Related QuestionHow to implement the followingHow to fix this
Best Answer