MAtlab finds the maximum value of a function and the corresponding independent variables

Find the extreme value:

clear
clc
t1= -100:0.001:100;
t2= -100:0.001:100;

syms x1;
syms x2;
y = 9.434-1980.396*x1+2619.34*x2;
f = inline(y);

max = max(f(t1,t2))
min = min(f(t1,t2))

The running results are as follows:
Insert image description here

Find the independent variable corresponding to the extreme value:

syms x1,x2;
y = 9.434-1980.396*x1+2619.34*x2==6.3904e+04;
x = vpasolve(y,x1,x2);
x.x1
x.x2

The running results are as follows:
Insert image description here

You can go here:

t1= -100:0.001:100;
t2= -100:0.001:100;

Change the value range of the variable to get different results.

Guess you like

Origin blog.csdn.net/qq_52626583/article/details/126225292