Applying a negative to the function to find the maximum

4 ビュー (過去 30 日間)
Gavin Seddon
Gavin Seddon 2015 年 8 月 20 日
回答済み: siscovic 2017 年 11 月 11 日
hello to find the maximum point in a curve I must use the negative function however this creates errors. My function is f = @(x)p1*x^4 + p2*x^3 + p3*x^2 + p4*x + p5 where does the minus sign precede the f? Thanks.

採用された回答

Titus Edelhofer
Titus Edelhofer 2015 年 8 月 20 日
Hi,
your minus should span the entire function, i.e.
f = @(x) -(p1*x^4 + p2*x^3 + p3*x^2 + p4*x + p5);
Titus

その他の回答 (4 件)

Steven Lord
Steven Lord 2015 年 8 月 20 日
If you don't want to recreate the function handle as Titus suggested, create a new function handle that calls the existing function handle and negates that function's output:
minusF = @(x) -f(x);

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 8 月 20 日
f=@(x)p1*x^4+p2*x^3+p3*x^2+p4*x+p5
h=@(x)-f(x)

Gavin Seddon
Gavin Seddon 2015 年 8 月 21 日
Many thanks for all these answers; this was what I was after Titus. I will implement your suggestion Stephen. Thank you again.

siscovic
siscovic 2017 年 11 月 11 日
Hello, how to calculate the gradient, Hessian matrix, of this function.Thank you
f=@(x) (x(1)-2)^4+(x(1)-2)^2*x(2)^2+(x(2)+1)^2

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by