Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Optimization on fminsearch

Subject: Optimization on fminsearch

From: June Goh

Date: 12 Oct, 2010 14:50:04

Message: 1 of 2

Hi,

Currently I'm student and required Matlab program to compute parameters of my project.

Following is the program code:

>>x0=[0.026 0];
>>[xx fval]=fminsearch(@A2_sumerr,x0,options,Start,End,G,YDATA);

>>function sum= A2_sumerr(x0,Start,End,G,YDATA)
>>sum=0; %Initialise the sum of error
>>for a=Start:1:End
>> f(a)=x0(1)*((log(YDATA(a)/(x0(2)))-2)(YDATA(Start)/YDATA(a))*(log(YDATA(Start)/(x0(2)))-2));
>> g(a)=G(a);
>> Error=g(a)-f(a);
>> sum=sum+Error^2;
>>end

>>end

Start, End, G and YDATA are the extra input parameters for function sum. The purpose of this program is to optimize x0 value, such that i can obtained sum as the lowest possible value(approximately to 0). However, I could not get what i needed.

I would like to enquire that, can the optimization of this program make sure that sum will obtain 0 with the adjustment of x0? Or is there a better method to make that that sum will eventually goes to 0 with the optimized x0?

Hope someone could help me with this.

Thanks in advance.

Subject: Optimization on fminsearch

From: Miroslav Balda

Date: 13 Oct, 2010 19:10:05

Message: 2 of 2

"June Goh" <gohm0022@e.ntu.edu.sg> wrote in message <i91sis$mbu$1@fred.mathworks.com>...
 SNIP

Hi June

Your code could not work because of errors:
1. It does not have a form required for any optimization function .
2. the command for evaluating f(a) is not a MATLAB statement due to missing bractets and an operator between the first and second term. Maybe that it could have the following form:
     f(a)=x0(1)*(log(YDATA(a)/(x0(2)))-2) - (YDATA(Start)/YDATA(a))*...(log(YDATA(Start)));

The solution of your problem could be found by the following code for MATLAB 7.x:

function [x,ssq,cnt] = driver(Ydata,G,p0)
% DRIvER Driver for parameter transfer to nested fuction res.m
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    [x,ssq,cnt] = LMFnlsq(@fun,p0,'Display',-10); % FEX Id 17534

    function res = fun(x0)
    % FUN Function for evaluating equation residuals
    %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    res = x0(1)*(log10(Ydata/(x0(2)))-2) - ...
          (Ydata(1)./Ydata)*(log10(Ydata(1))) - G;
    end % res
end % driver

It is necessary to call the function driver.m as it follows:

p0 = .....; % Initial estimate of the solution, rand(2,1) if no feeling
G = G(:); % make column vector G
YDATA = YDATA(:); % make column vector YDATA
[x,ssq,cnt] = driver(YDATA(Start:End),G,p0)

It's all. Hope it will work.

Mira

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us