How to optimize a function?

f(x)=x^2+2x-3
x belong to [0,20]
i- How can I optimize the function in matlab?

3 Comments

Stephen23
Stephen23 on 14 May 2018
Edited: Stephen23 on 14 May 2018
@Noor Bano: what does "optimize the function" mean? What is the output that you want from this?
How to maximize a function, or how to minimize a function, or in other words on which x value the function gives maximum or minimum value.
Use "fmincon" with the bound constraints x>=0 and x<=20.

Sign in to comment.

 Accepted Answer

x1=0;
x2=20;
fun=@(x)x^2+2x-3;
x = fminbnd(fun,x1,x2)

More Answers (0)

Asked:

on 14 May 2018

Commented:

on 14 May 2018

Community Treasure Hunt

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

Start Hunting!