Fitting specific level of contour plot to data

조회 수: 2 (최근 30일)
Rafegh Aghamohammadi
Rafegh Aghamohammadi 2021년 2월 14일
답변: Nipun 2024년 5월 31일
Hi all,
I have some data (shown in yellow and blue dots) and I want to fit a specific level (0.5) of a contour plot of a function to it. The function has 6 input variables and what I want to do is to find the set of input variables resulting in the optimum fit of the 0.5 contour plot of the function to the data. Is there any way to do such thing in MATLAB? Thank you, in advance, for your time!

답변 (1개)

Nipun
Nipun 2024년 5월 31일
Hi Rafegh,
I understand that you want to fit a specific level (0.5) of a contour plot to your data (shown in yellow and blue dots) and find the optimal set of input variables for a function with 6 input variables. Here's a way to do it in MATLAB:
  1. Define your function.
  2. Create a function to calculate the difference between your data and the 0.5 contour level.
  3. Use fmincon to minimize this difference and find the optimal input variables.
Here's an example code:
% Example function with 6 input variables
myFunction = @(x1, x2, x3, x4, x5, x6, X, Y) ... % define your function
% Objective function to minimize the difference to the 0.5 contour
objective = @(vars) sum((myFunction(vars(1), vars(2), vars(3), vars(4), vars(5), vars(6), X, Y) - 0.5).^2);
% Initial guess for the variables
initialGuess = [1, 1, 1, 1, 1, 1];
% Optimization options
options = optimoptions('fmincon', 'Display', 'iter', 'Algorithm', 'interior-point');
% Run the optimization
optimalVars = fmincon(objective, initialGuess, [], [], [], [], [], [], [], options);
% Display the optimal variables
disp('Optimal variables:');
disp(optimalVars);
You can refer to the MathWorks documentation for more details on fmincon: https://www.mathworks.com/help/optim/ug/fmincon.html
Hope this helps.
Regards,
Nipun

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by