MATLAB Optimization: Wots wrong with my MATLAB CODE

AI Thread Summary
The discussion revolves around a user seeking help with optimization using the Golden-section method to find the minimum of the function f(x) = x^2 - 3xe^-x within the interval [0, 1]. The user expresses frustration over running out of ideas and is struggling with the implementation of their function. They provide a code snippet but do not clarify the specific issues they are encountering. Another participant suggests that a clearer explanation of the problem would facilitate better assistance. The conversation highlights the importance of detailed communication when seeking help with programming and optimization challenges.
mooberrymarz
Messages
53
Reaction score
0
Optimization: I am going insane here

:cry: :cry: 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:
Physics news on Phys.org
oh yeah, I had to use Golden-section to find the min of f(x)=x^2 - 3xe^-x in the interval [0,1]
......I shalll now open a fortune cookie....

and it says that i am sooooo buggered if u don't help me.
 
Last edited:
Why don't you try to actually explain to us what you're trying to do, and why exactly it's not working as you'd like? That sure would help.

- Warren
 

Similar threads

Back
Top