MATLAB: How to calculate the minimum of a function of two variables MATLABminimum Hello, I am new to Matlab and encountering some difficulties Computing the minimum of a function of two variables: f(x,y)= e^(x-y) + x^2 + y^2. Also is it possible to plot the resulting surface around the minimum? Best Answer One approach: syms x y f(x,y) = exp(x-y) + x^2 + y^2;Dfx = diff(f, x)D2fx = diff(Dfx,x)Dfy = diff(f, y)D2fy = diff(Dfy, y)Inflpt = solve(Dfx, Dfy, [x,y])xs = Inflpt.xys = Inflpt.yCheck = [D2fx(xs,ys); D2fy(xs,ys)]figurefsurf(f, double([xs-2 xs+2 ys-2 ys+2]))Since ‘Check’ is positive for both functions, ‘Inflpt’ is a minimum. EDIT — Added plot figure — Related SolutionsMATLAB: Derivative firstly x then y Using symbolic toolbox, you can do it like thissyms x yf = (x^28)/(y^2+x^2)+(sqrt(exp(x*y)+abs(-4*y)));fx = diff(f, x); % derivative w.r.t. xfy = diff(f, y); % derivative w.r.t. yOutput from live scriptdisp(f)disp(fx)disp(fy) MATLAB: Plotting on scatter in malab Change the last part of code like this%%Filtering Resultsidx = any(possibleSol < 0) | any(imag(possibleSol) ~=0);possibleSol(:, idx) = [];fprintf('Xs=%.f\nYs=%.f\nZs=%.f\n', possibleSol);ax = axes();hold ongrid onview(3);plot3(x,y,z, 'ro', 'LineWidth', 2, 'MarkerSize', 10)plot3(possibleSol(1),possibleSol(2),possibleSol(3), 'b+', 'LineWidth', 2, 'MarkerSize', 10) Related QuestionHello, I want to derive from a function such as (f=f0+R*f1+R^2*f2+R^3*f3) so that the answer is as follows: (f’=f0’+R*f1’+R^2*f2’+R^3*f3′)Trying to find all critical points where gradient f = 0 but am getting an error.Differential equation with mixed linear and log derivatives – proper setting
Best Answer