WICHTIG: Der Betrieb von goMatlab.de wird privat finanziert fortgesetzt. - Mehr Infos...

Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

Polynomfit klappt nicht

 

HeikeMareike

Gast


Beiträge: ---
Anmeldedatum: ---
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 01.03.2016, 21:34     Titel: Polynomfit klappt nicht
  Antworten mit Zitat      
Hallo Leute,

ich stehe gerade vor einem (kleinen?) Problem. - Ich habe verschiedene Datenpunkte zu bestimmten Zeitpunkten vorliegen, welche ich allesamt jeweils mit einer Polynomfunktion in 2 Variablen fitte. (Siehe Minimalbeispiel). - Das funktioniert soweit ganz gut; ich verwende hierzu die Funktion polyfitn().

Problematisch ist nun, dass die Zahlen, die das Array "tofit" enthält sukzessive kleiner werden, sodass irgendwann einmal alle Einträge 0 sind. Dies führt zu einem Absturz mit der Fehlermeldung

Code:

Error using betainc
X must be in the interval [0,1].

Error in polyfitn (line 233)
polymodel.p = betainc(polymodel.DoF./(t.^2 + polymodel.DoF),polymodel.DoF/2,1/2);

Error in polyfittest (line 37)
p = polyfitn([xpfit(:), ypfit(:)], tofit(:),poly44);
 


Hat jemand von Euch eine Idee, wie ich diesen Fehler abfangen kann bzw. wie ich den Fit dennoch schaffe? (Letztlich ist es ja "nur" eine Ebene, die im Ursprung des Koordinatensystems, liegt und von der x- und y-Achse aufgespannt wird.)

Über Hilfe wäre ich dankbar,
mlg,
HeikeMareike

---

Hier das Minimalbeispiel. (Der Fehler kann erzeugt werden, indem der Multiplikator vor "tofit" auf 0.0 gesetzt wird):

Code:

% Polyfitn test

% Grad des Polynoms in jeweilige Fitrichtung
poly22 = 'constant, x, y, x^2, x*y, y^2';

poly23 = 'constant, x, y, x^2, x*y, y^2, y*x^2, x*y^2, y^3';
poly32 = 'constant, x, y, x^2, x*y, y^2, x^3, y*x^2, x*y^2';
poly33 = 'constant, x, y, x^2, x*y, y^2, x^3, y*x^2, x*y^2, y^3';

poly24 = 'constant, x, y, x^2, x*y, y^2, y*x^2, x*y^2, y^3, x*x*y*y, x*y^3, y^4';
poly42 = 'constant, x, y, x^2, x*y, y^2, x^3, y*x^2, x*y^2, x^4, y*x^3, x*x*y*y';
poly44 = 'constant, x, y, x^2, x*y, y^2, x^3, y*x^2, x*y^2, y^3, x^4, y*x^3, x*x*y*y, x*y^3, y^4';

% Koordinaten und Werte der zu fittenden Daten
xpfit = [0 1 2 3 4;
         0 1 2 3 4;
         0 1 2 3 4;
         0 1 2 3 4;
         0 1 2 3 4;
         0 1 2 3 4 ];
     
ypfit = [1 1 1 1 1;
         2 2 2 2 2;
         3 3 3 3 3;
         4 4 4 4 4;
         5 5 5 5 5;
         6 6 6 6 6 ];

tofit = 0.6*[ 1 1 1 1 1;
          2 2 2 2 2;
          3 3 3 3 3;
          4 4 4 4 4;
          5 5 5 5 5;
          6 6 6 6 6 ];

% Fitten mit Polyfit
p = polyfitn([xpfit(:), ypfit(:)], tofit(:),poly44);

if exist('sympoly') == 2
   
    polyn2sympoly(p);
   
end

if exist('sym') == 2
   
    polyn2sym(p);
   
end


% Plotten
[xPfit, yPfit] = meshgrid(0:0.1:4, 1:0.1:6);
zgrid = polyvaln(p, [xPfit(:), yPfit(:)]);

surf(xPfit, yPfit, reshape(zgrid, size(xPfit)));
hold on
surf(xpfit, ypfit, tofit, ...
    'facecolor', 'green');
xlabel('x ...');
ylabel('y ...');
zlabel('tofit');
hold off
 


Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

Du kannst Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.
Du kannst Dateien in diesem Forum posten
Du kannst Dateien in diesem Forum herunterladen
.





 Impressum  | Nutzungsbedingungen  | Datenschutz | FAQ | goMatlab RSS Button RSS

Hosted by:


Copyright © 2007 - 2025 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks

MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.