You may be interested in the function optimize. This looks like it may be homework so I'll suggest you read the documentation on that and see if you can get it to work, and if you have some specific difficulty come back here and post the code you tried, describe the specific problem you are having, etc.