Lsqcurvefit - multiple parameters - two variables (2024)

32 Ansichten (letzte 30 Tage)

Ältere Kommentare anzeigen

Cyril GADAL am 15 Mai 2017

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/340350-lsqcurvefit-multiple-parameters-two-variables

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/340350-lsqcurvefit-multiple-parameters-two-variables

Kommentiert: Cyril GADAL am 16 Mai 2017

Akzeptierte Antwort: Torsten

In MATLAB Online öffnen

Hello,

I'm currently working on a function of two variables of the type z=f(x,y), controlled by 4 parameters, and I would like to fit data I obtained to my theoretical function. I read detailed post about how to dit with lsqcurvefit, but a problem remains. This is how I did :

function Sigma = Sigma_funct(p,Var)

Sigma = f(p(1),p(2),p(3),p(4), x,y)

end

with lets say Var(1) = x and Var(2) = y. Then, I'm supposed to use the following syntax :

p0 = [3,1,2,10] ;

x = lsqcurvefit(@Sigma_funct,p0,[x y],Sigma_data) ;

However, my problem is that x and y have different size, meaning that Sigma_data isn't a squared matrix : I can't concatenate x and y. How am I supposed to do ?

Thanks for your answers !

P.S : Just to say it, f is linear neither in parameters nor in variables.

2 Kommentare

Keine anzeigenKeine ausblenden

Torsten am 16 Mai 2017

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/340350-lsqcurvefit-multiple-parameters-two-variables#comment_454265

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/340350-lsqcurvefit-multiple-parameters-two-variables#comment_454265

It's not clear what the size of the matrix "Sigma_data" is and what it contains.

Best wishes

Torsten.

Cyril GADAL am 16 Mai 2017

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/340350-lsqcurvefit-multiple-parameters-two-variables#comment_454278

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/340350-lsqcurvefit-multiple-parameters-two-variables#comment_454278

Bearbeitet: Cyril GADAL am 16 Mai 2017

You're right. So I have a vector x of size N and y of size M such that Sigma_data is of size N*M : I would then have for the theoretical values Sigma(i,j) = f(xi, xj) and then would like to fit this to Sigma_data using lsqcurvefit.

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Akzeptierte Antwort

Torsten am 16 Mai 2017

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/340350-lsqcurvefit-multiple-parameters-two-variables#answer_267206

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/340350-lsqcurvefit-multiple-parameters-two-variables#answer_267206

In MATLAB Online öffnen

p0 = [3,1,2,10] ;

xdata = zeros(numel(x)*numel(y),1);

ydata = reshape(Sigma_data,[numel(x)*numel(y),1]);

p_sol = lsqcurvefit(@(p,xdata)Sigma_funct(p,xdata,x,y),p0,xdata,ydata);

function Sigma = Sigma_funct(p,xdata,x,y)

Sigma_mat = f(p(1),p(2),p(3),p(4),x,y)

Sigma = reshape(Sigma_mat,[numel(x)*numel(y),1]);

end

Best wishes

Torsten.

5 Kommentare

3 ältere Kommentare anzeigen3 ältere Kommentare ausblenden

Cyril GADAL am 16 Mai 2017

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/340350-lsqcurvefit-multiple-parameters-two-variables#comment_454299

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/340350-lsqcurvefit-multiple-parameters-two-variables#comment_454299

Oh right. So everything has to be column vectors. I just do not understand why xdata is full of zeros ?

Torsten am 16 Mai 2017

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/340350-lsqcurvefit-multiple-parameters-two-variables#comment_454305

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/340350-lsqcurvefit-multiple-parameters-two-variables#comment_454305

Because in your case, there is no senseful "xdata" vector.

Sigma_data depends on x and y, but what scalar value could you choose that Sigma_mat(i,j) depends on ?

Anyway, you can define "xdata" to be an arbitrary N*M-vector - it has no influence on the parameter estimation.

Best wishes

Torsten.

Cyril GADAL am 16 Mai 2017

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/340350-lsqcurvefit-multiple-parameters-two-variables#comment_454338

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/340350-lsqcurvefit-multiple-parameters-two-variables#comment_454338

I'm sorry, I don't get it ... Are xdata not supposed to be representing the variables leading to ydata ? As the time for example if I look at a time serie, or the distance if I look at a 2D topography ?

Thank you for your answers by the way, that was really helpfull !

Torsten am 16 Mai 2017

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/340350-lsqcurvefit-multiple-parameters-two-variables#comment_454349

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/340350-lsqcurvefit-multiple-parameters-two-variables#comment_454349

Bearbeitet: Torsten am 16 Mai 2017

In MATLAB Online öffnen

The only thing that matters for "lsqcurvefit" is how the ydata-vector depends on the parameter vector.

The xdata-vector is only introduced to make things easier for you if the relationship between parameter vector and ydata-vector can be established easily by an equation of the form

ydata(i) = func(p,xdata(i)) (i=1,...,N*M)

e.g. for linear regression ydata(i) = p(1)+p(2)*xdata(i).

But this is not the case for your problem - so don't worry about the "xdata"-vector.

Best wishes

Torsten.

Cyril GADAL am 16 Mai 2017

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/340350-lsqcurvefit-multiple-parameters-two-variables#comment_454352

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/340350-lsqcurvefit-multiple-parameters-two-variables#comment_454352

Understood.

Thank you very much for your time !

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Melden Sie sich an, um diese Frage zu beantworten.

Siehe auch

Kategorien

AI, Data Science, and StatisticsCurve Fitting ToolboxGet Started with Curve Fitting Toolbox

Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Help Center und File Exchange

Tags

  • curve fitting
  • function
  • surface

Community Treasure Hunt

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

Start Hunting!

Es ist ein Fehler aufgetreten

Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.


Translated by Lsqcurvefit - multiple parameters - two variables (10)

Lsqcurvefit - multiple parameters - two variables (11)

Website auswählen

Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .

Sie können auch eine Website aus der folgenden Liste auswählen:

Amerika

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europa

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asien-Pazifik

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Kontakt zu Ihrer lokalen Niederlassung

Lsqcurvefit - multiple parameters - two variables (2024)

References

Top Articles
Latest Posts
Article information

Author: Kareem Mueller DO

Last Updated:

Views: 5971

Rating: 4.6 / 5 (66 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Kareem Mueller DO

Birthday: 1997-01-04

Address: Apt. 156 12935 Runolfsdottir Mission, Greenfort, MN 74384-6749

Phone: +16704982844747

Job: Corporate Administration Planner

Hobby: Mountain biking, Jewelry making, Stone skipping, Lacemaking, Knife making, Scrapbooking, Letterboxing

Introduction: My name is Kareem Mueller DO, I am a vivacious, super, thoughtful, excited, handsome, beautiful, combative person who loves writing and wants to share my knowledge and understanding with you.