Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

function f = myfun(x)

f = x^2;

>> myfun(2)

ans =

>> myfun(6)

ans =

36

>> x = fminbnd(@myfun,-1,1)

x=

-2.7756e-017

>> x = fminbnd(@myfun,-1,1)

x=

-2.7756e-017

>> x=-1:0.1:1
x=

Columns 1 through 7

-1.0000 -0.9000 -0.8000 -0.7000 -0.6000 -0.5000 -0.4000

Columns 8 through 14

-0.3000 -0.2000 -0.1000 0 0.1000 0.2000 0.3000

Columns 15 through 21

0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1.0000

>> y=x.2

??? y=x.2

Error: Missing MATLAB operator.

>> y=x.^2

y=

Columns 1 through 7

1.0000 0.8100 0.6400 0.4900 0.3600 0.2500 0.1600


Columns 8 through 14

0.0900 0.0400 0.0100 0 0.0100 0.0400 0.0900

Columns 15 through 21

0.1600 0.2500 0.3600 0.4900 0.6400 0.8100 1.0000

>> plot(x,y)

>> hold on

>> x = fminbnd(@myfun,-1,1)

x=

-2.7756e-017

>> plot(x,myfun(x),'*r')

>>

You might also like