Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9135413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:49:15+00:00 2026-06-17T08:49:15+00:00

I want to fit some data to a lorentz function but I figure problems

  • 0

I want to fit some data to a lorentz function but I figure problems with fitting when I use parameters which are of different orders of magnitude.

This my lorentz function:

function [ value ] = lorentz( x,x0,gamma,amp )
    value = amp * gamma^2 ./ ((x-x0).^2 + gamma^2);
end

Now the script to generate sample data:

x = linspace(2e14,6e14,200);
x0 = 4.525e14;
gamma = 0.5e14;
amp = 2e-14;

y = lorentz(x,x0,gamma,amp);

And the script for fitting lorentz to the sample data:

params = [4.475e14;0.4e14;1.8e-14];
opts = optimset('TolFun',1e-60,'TolX',1e-50,'Display','Iter');
fitfunc = @(params,x) lorentz(x,params(1),params(2),params(3));
fitparams = lsqcurvefit(fitfunc,params,x,y,[],[],opts)

figure(1);hold on;
plot(x,y,'.');
plot(x,lorentz(x,params(1),params(2),params(3)),'--');
plot(x,lorentz(x,fitparams(1),fitparams(2),fitparams(3)));
hold off;

This only varies the last parameter (the smallest, which is the amplitude). If I leave all exponentials out it works as expected. I assume there is some finetuning of opts to be done, but I don’t know how. Any ideas how to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:49:16+00:00Added an answer on June 17, 2026 at 8:49 am

    As you suggested, you’re going to run into numerical issues whenever you have parameters that vary over 28 (!) orders of magnitude. LSQCURVEFIT, for example, will try and estimate proper gradient steps, and those calculations may be sensitive to numerical stability (depending on the actual implementation – see http://en.wikipedia.org/wiki/Levenberg%E2%80%93Marquardt_algorithm for a summary of how all this is done).

    In my experience, you need to find a way to normalize the input parameters that make them more comparable. For example, you can take the log of all the values, and then exp() them inside you’re objective function.

    params = log([4.475e14;0.4e14;1.8e-14])
    

    and

    function [ value ] = lorentz( x,x0,gamma,amp )
        gamma = exp(gamma); 
        amp = exp(amp);
        x0 = exp(x0);
        value = amp * gamma^2 ./ ((x-x0).^2 + gamma^2);
    end
    

    That may introduce other instabilities, but it should get you started.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I had some data, for which I want to fit a parametrized model
I am fitting some data with a linear fit. I want to weight the
I have some historical data RV that I want to fit a model to.
I'm plotting some data sets with linear fits. I want the linear fit to
I want to generate a continuous curve based on some data, but the curve
I get some weird overflow whenever I want to fit an object inside foreignObject
I've a 1D list of data, that I want to fit into a distribution
I want do fit some sort of multi-variate time series model using R. Here
I am doing some data fitting using the pyminuit Python bindings for the minuit
I have some data which I am binding to a dropdown dynamically like this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.