Write a MATLAB code to Find the maxima and minima of two variable function f(x,y)=x^4+y^4-4xy+1

조회 수: 191 (최근 30일)
Find the maxima and minima of two variable function f(x,y)=x^4+y^4-4xy+1
  댓글 수: 2
Yusuf Suer Erdem
Yusuf Suer Erdem 2021년 12월 13일
Edit your question like this please;
How to write the MATLAB code to find the maximum and minimum output of a function with 2 variables;
f(x,y)=x^4+y^4-4*x*y+1
John D'Errico
John D'Errico 2021년 12월 15일
Please stop posting your homework assignment questions. Answers is not a service where we do your homework.

댓글을 달려면 로그인하십시오.

답변 (2개)

Yusuf Suer Erdem
Yusuf Suer Erdem 2021년 12월 13일
Hi Akinchay, try these codes below please;
clc;
clear;
close all;
xMin = -2;
xMax = 2;
yMin = -2;
yMax = 2;
numPoints = 200;
xv = linspace(xMin, xMax, numPoints);
yv = linspace(yMin, yMax, numPoints);
[x, y] = meshgrid(xv, yv);
% f(x,y) = x.^4 + y.^4 - 4.*x.*y + 1
fprintf('Creating function.\n');
f = x.^4 + y.^4 - 4.*x.*y + 1;
fprintf('Creating surface plot.\n');
surf(x, y, f, 'LineStyle', 'none');
xlabel('x', 'FontSize', 20);
ylabel('y', 'FontSize', 20);
zlabel('f', 'FontSize', 20);
title('f(x,y) = x.^4 + y.^4 - 4.*x.*y + 1', 'FontSize', 20);
colorbar;
maxValue = max(abs(f(:)));
minValue = min(abs(f(:)));
fprintf('The max of f = %f.\nThe min of f = %f.\n', maxValue, minValue);

Torsten
Torsten 2021년 12월 13일
편집: Torsten 2021년 12월 13일
syms x y f(x,y)
f(x,y)=x^4+y^4-4*x*y+1;
dfx=diff(f,x);
dfy=diff(f,y);
eqns=[dfx==0,dfy==0];
vars=[x y];
S=solve(eqns,vars,'Real',true)
@Yusuf Suer Erdem: I think local minima and maxima are meant in the exercise.
  댓글 수: 2
Yusuf Suer Erdem
Yusuf Suer Erdem 2021년 12월 14일
@Torsten Hi Torsten, if it is asked local maxima and local minima, you are right. Determining the points where diff(f)==0 will give us local minima and maxima.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by