How do i use fminsearch to find the minimum or maximum of a function . x.^4-3.*x.*y+2.*y.^2
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I trying to use fmin search for a function of 2 variable
Risposta accettata
James Tursa
il 13 Ott 2022
Modificato: James Tursa
il 13 Ott 2022
You need to have your function handle accept a vector and return a scalar. I.e., the x argument to the function handle is a vector of two elements representing your original x and y variables. Assuming x(1) and x(2) are your intended original x and y variables, that would mean something like this:
fun = @(x) x(1).^4-3.*x(1).*x(2) +2.*x(2).^2;
x0 = [-0.5,0.5];
x = fminsearch(fun,x0)
3 Commenti
James Tursa
il 13 Ott 2022
Modificato: James Tursa
il 13 Ott 2022
format longg
fun = @(x) x(1).^4-3.*x(1).*x(2) +2.*x(2).^2;
x0 = [-0.5,0.5];
x = fminsearch(fun,x0)
fun(x)
fun([3/4,9/16])
Also note that fminsearch( ) can only find local minimums, of which there can be more than one depending on the function. So different starting points can result in different answers.
x = fminsearch(fun,[3/4+0.1,9/16-0.1])
fun(x)
Più risposte (1)
the cyclist
il 13 Ott 2022
Modificato: the cyclist
il 13 Ott 2022
Did you try reading the documentation for fminsearch? The very first example is exactly like your problem.
fun = @(x)(x(1)^4 - 3*x(1)*x(2) + 2*x(2)^2);
x0 = [-0.5, 0.5];
x = fminsearch(fun,x0)
0 Commenti
Vedere anche
Categorie
Scopri di più su Calculus in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!