CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: How to optimize a lsqnonlin function in matlab?

  1. #1
    Join Date
    Jun 2018

    How to optimize a lsqnonlin function in matlab?

    I have a set of parameters that I want to have them returned as result of the non-linear optimization through, the function *lsqnonlin*. The code is for an inverse problem, which gives a set of ThermoMechanical parameters in function of the displacement of a metallic bar. The problem, is that the optimization returns to me an aproximated value or almost the same as the starting point (X0). When it should be giving the result equal or aproximate to those of the variables. For that, I tried the input argument 'options', trying to change the number of MaxIter, MaxFunEval and the function tolerance. As a result of the program it alxays gives the same anszer:"*Optimization completed because the size of the gradient is less than
    the default value of the optimality tolerance.*" What can I do to improve the optimization? Thank you for your help.

    tf = 20;

    Texcel = xlsread ('Classeur(19_04).xls',1,'L2:L202');
    ResSpline = spline (t,Texcel);

    ParamThermMec; %Thermo-mechanical parameters defined by the array X0=[coeff_dilat G Cp lanbda Rho]
    nu = 0.3; %Poisson's coefficient
    Ucomsol = xlsread ('Classeur(19_04).xls',2,'L2:L202'); %displacement from Classeur(19_04).xls

    figure (1)
    hold on
    yyaxis left
    plot (t,Ucomsol)
    yyaxis right
    plot (t,Texcel)
    xlim([0 20])

    fun = @(X)(deplacement_lsq(0,ResSpline,X)-Ucomsol); %function to minimize
    [temps,Umatlab_bauzin] = DeplacementSpline(0,ResSpline,1);

    X0 = X/2; %initial value or starting point

    [ParametresTM,resnorm,residual,exitflag,output]=lsqnonlin(fun,X0,[0 0 0 0 0],[10 999999999999 2500 500 4000],options); %nonlinear minimisation
    EX=[DiffXP(1)/X(1) DiffXP(2)/X(2) DiffXP(3)/X(3) DiffXP(4)/X(4) DiffXP(5)/X(5)]*100; %Percentage difference

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012

    Re: How to optimize a lsqnonlin function in matlab?

    [moved from c++ as matlab]
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.8.1)

  3. #3
    Join Date
    Jun 2018

    Re: How to optimize a lsqnonlin function in matlab?

    But after optimising it my system screen turns blue why this is happening?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)