- #1
mooberrymarz
- 53
- 0
Optimization: I am going insane here
I've really run out of ideas... please help me.!
%golden.m
function [f,a]=golden(func,p,tol)
func='dfunc';
p=[0 1]
g=0.38;
a=p(1);
b=p(2);
r=b-a
tol=0.01;
iter=0
while r>tol
x=[a+g*r b-g*r]
y=feval(func,x)
if y(1)<y(2)
b=x(2);
else
a=x(1);
end
r=b-a;
iter=iter+1;
end
iter
f=feval (func, a);
%dfunc.mfunction
q=dfunc(x)
q=x'*x-3*x*(exp^-x);
I've really run out of ideas... please help me.!
%golden.m
function [f,a]=golden(func,p,tol)
func='dfunc';
p=[0 1]
g=0.38;
a=p(1);
b=p(2);
r=b-a
tol=0.01;
iter=0
while r>tol
x=[a+g*r b-g*r]
y=feval(func,x)
if y(1)<y(2)
b=x(2);
else
a=x(1);
end
r=b-a;
iter=iter+1;
end
iter
f=feval (func, a);
%dfunc.mfunction
q=dfunc(x)
q=x'*x-3*x*(exp^-x);
Last edited: