Clear Filters
Clear Filters

lsqnonlin-surface plot

8 views (last 30 days)
Malgorzata Wieteska
Malgorzata Wieteska on 9 Mar 2021
Answered: Nipun on 14 May 2024
Hello,
I would like to visualise using the surface plot if my optimisation using lsqnonlin found a global solution and if there are other minima. I have ODE system with 2 DE. I have obtained the vector of data for each DE equation (solved with the optimised values of the parameters)).
I've tried to search on the web, but I can't find anything relevant, which would work.
Thanks in advance
  1 Comment
Alan Weiss
Alan Weiss on 10 Mar 2021
Sorry, I don't understand what you are trying to achieve. How many variables do you have for the plot? What is the response that you want to plot? For example, an ODE can often be visualized using a vector field plot, but not in more than 3 dimensions. But you have lsqnonlin on top of a system of differential equations, and I don't know what you would like to plot.
Alan Weiss
MATLAB mathematical toolbox documentation

Sign in to comment.

Answers (1)

Nipun
Nipun on 14 May 2024
Hi Malgorzata,
I understand that you want to visualize the optimization landscape of your system of two differential equations to determine if the optimization process using lsqnonlin has found a global solution and to identify if there are other local minima. This involves creating a surface plot over a range of your parameter values to see the sum of squared residuals or your specific objective function's values, giving insight into the nature of the solution space.
To achieve this, follow these steps:
1. Define the Parameter Ranges
First, decide on reasonable ranges for the parameters you've optimized in your ODE system. This step is crucial as it sets the domain over which you'll plot your surface.
p1_range = linspace(start_p1, end_p1, 100); % Define a reasonable range for the first parameter
p2_range = linspace(start_p2, end_p2, 100); % Define a reasonable range for the second parameter
2. Compute the Objective Function Over the Grid
Assuming you have an objective function that calculates the sum of squared residuals for given parameter values (let's call this function obj_fun(p1, p2)), you'll compute this function across a grid defined by your parameter ranges.
[P1, P2] = meshgrid(p1_range, p2_range);
Residuals = zeros(size(P1)); % Preallocate for efficiency
for i = 1:size(P1, 1)
for j = 1:size(P1, 2)
Residuals(i, j) = obj_fun(P1(i, j), P2(i, j)); % Compute objective function for each parameter pair
end
end
3. Generate the Surface Plot
With the computed values, you can now generate a surface plot that visualizes the optimization landscape:
surf(P1, P2, Residuals)
xlabel('Parameter 1')
ylabel('Parameter 2')
zlabel('Sum of Squared Residuals')
title('Optimization Landscape')
colorbar
This visualization will help you identify valleys, or minima, in the optimization landscape. The global minimum, if identifiable through this method, will be the lowest point on this surface. However, keep in mind that visually distinguishing between local and global minima can be challenging, especially in complex landscapes. This method is a powerful tool for gaining insights into the behavior of your optimization process and the nature of the solution space.
Hope this helps.
Regards,
Nipun

Community Treasure Hunt

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

Start Hunting!