matlab simultaneous fitting of exponential to surface in matlab

To perform simultaneous fitting of exponential functions to a surface in MATLAB, you can use the 'lsqcurvefit' function combined with a custom model function for fitting. Here's a step-by-step guide:

  1. Define your custom model function that represents the surface as an exponential:
main.m
function y = exponentialSurfaceModel(x, params)
% x: input variables (e.g., x and y coordinates)
% params: parameters of the surface model

% Extract parameters
a = params(1);
b = params(2);
c = params(3);

% Calculate the surface using the exponential equation
y = a * exp(-b * x(:,1)) .* exp(-c * x(:,2));
end
312 chars
13 lines
  1. Generate noisy surface data for fitting. This can be done by evaluating the model function with some input variables and adding noise:
main.m
% Generate input data
x1 = linspace(0, 1, 100);
x2 = linspace(0, 1, 100);
[X1, X2] = meshgrid(x1, x2);
x = [X1(:), X2(:)];

% Set true parameters for the surface model
trueParams = [2, 3, 4];

% Generate surface data based on the true parameters
yTrue = exponentialSurfaceModel(x, trueParams);

% Add noise to the surface data
noiseStd = 0.1; % standard deviation of the noise
yNoisy = yTrue + noiseStd * randn(size(yTrue));
425 chars
16 lines
  1. Define the objective function for fitting, which calculates the residuals between the observed data and the model predictions:
main.m
function residuals = exponentialSurfaceResiduals(params, x, yObserved)
% params: parameters of the surface model
% x: input variables
% yObserved: observed data

% Calculate the predictions of the model
yPredicted = exponentialSurfaceModel(x, params);

% Calculate the residuals
residuals = yPredicted - yObserved;
end
319 chars
12 lines
  1. Perform the simultaneous fitting using the 'lsqcurvefit' function:
main.m
% Initial guess for the parameters
initialParams = [1, 1, 1]; % adjust according to your data

% Run the simultaneous fitting
paramsEst = lsqcurvefit(@exponentialSurfaceModel, initialParams, x, yNoisy, [], [], options);
220 chars
6 lines

Make sure to adjust the 'initialParams' and the 'x' and 'yNoisy' inputs according to your specific data. The 'options' argument in the 'lsqcurvefit' function can be used to set various fitting options, such as the maximum number of iterations and the display level.

After the fitting process, the estimated parameters 'paramsEst' will correspond to the best-fit exponential surface model.

Note: Depending on the nature of your surface and the specific fitting requirements, you might need to modify the model function and the fitting approach accordingly.

gistlibby LogSnag