Optimization: Wots wrong with my MATLAB CODE

Click For Summary
SUMMARY

The forum discussion centers around optimizing a MATLAB code using the Golden-section search method to find the minimum of the function f(x) = x^2 - 3xe^-x within the interval [0, 1]. The user is struggling with the implementation of the golden.m and dfunc.m functions, specifically in how to correctly evaluate the function and update the interval based on the results. Key issues include incorrect function evaluation and the need for clearer explanations of the intended functionality.

PREREQUISITES
  • Understanding of MATLAB programming and syntax
  • Familiarity with optimization techniques, specifically the Golden-section search
  • Knowledge of function evaluation in MATLAB using feval
  • Basic calculus concepts related to finding minima of functions
NEXT STEPS
  • Review MATLAB documentation on function handles and feval for better function evaluation
  • Study the Golden-section search algorithm in detail to understand its implementation
  • Learn about MATLAB debugging techniques to identify and fix code errors
  • Explore alternative optimization methods available in MATLAB, such as fminunc or fmincon
USEFUL FOR

This discussion is beneficial for MATLAB programmers, particularly those focused on numerical optimization, as well as students and professionals looking to enhance their understanding of optimization algorithms in MATLAB.

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

  • · Replies 4 ·
Replies
4
Views
2K
Replies
5
Views
3K
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
10K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 10 ·
Replies
10
Views
3K