graphing norm of residuals

14 views (last 30 days)
MOH
MOH on 28 Oct 2021
Commented: Walter Roberson on 28 Oct 2021
I used the fminseach to fit non linear equation , how I can graph the residuals . when I seached it I saw it in the graph tool box . how I can graph it if I'm not using the tool box?
  2 Comments
Bjorn Gustavsson
Bjorn Gustavsson on 28 Oct 2021
Do you mean graph the residuals as fminsearch progresses? Or graph the different terms that goes into your non-linear equation? Or something else?
MOH
MOH on 28 Oct 2021
Graphing the residuals as fminsearch progresses

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 28 Oct 2021
You can create an options structure that specifies PlotFcn https://www.mathworks.com/help/matlab/math/plot-functions.html
You can create a custom plot function; https://www.mathworks.com/help/optim/ug/output-function.html
The particular field you would want to plot is named fval
  5 Comments
Walter Roberson
Walter Roberson on 28 Oct 2021
I posted the link above to the structure needed for custom plot functions; you would create such a function (start by copying optimplotfval) and then you would specify it as a PlotFcn in your options.
The difference compared to the existing optimplotfval is that you would need to deliberately plot abs(fval) and so would have the odd situation where the plot would get worse as the fval got more negative.
If you are certain that the output of your function is strictly non-negative, then you can just specify @optimplotfval as your PlotFcn in your options, without having to do anything more. This would not strictly be norm(fval) but it would have the same output provided that the function is strictly >= 0
Walter Roberson
Walter Roberson on 28 Oct 2021
Perhaps you have structured your search along the lines of
[bestpara, bestresidue] = fminsearch(@(parameters) objective(parameters, xdata, ydata), x0);
function residue = objective(parameters, xdata, ydata)
predictions = some function of parameters and xdata
residue = norm(predictions - ydata);
end
If so then to plot the residues, add options to the fminsearch call with 'PlotFcn' of @optimplotfval .

Sign in to comment.

More Answers (0)

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!