graphing norm of residuals
14 views (last 30 days)
Show older comments
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
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?
Accepted Answer
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
The particular field you would want to plot is named fval
5 Comments
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
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 .
More Answers (0)
See Also
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!