System of equations { parametic & using 5 polynomial solve } not working
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
My system of equations is yielding inaccurate results. Where N is a 400 x 3 matrix (x,y,z points) and P0 and P1 are points on a line we are trying to find the line - surface intersect for.
sS = size(N);
if sS(1) < sS(2)
N = N';
end
X = N(:,1);
Y = N(:,2);
Z = N(:,3);
[s,gof] = fit([X, Y],Z,'poly55');
s1(1) = s.p00;
s1(2) = s.p10;
s1(3) = s.p01;
s1(4) = s.p20;
s1(5) = s.p11;
s1(6) = s.p02;
s1(7) = s.p30;
s1(8) = s.p21;
s1(9) = s.p12;
s1(10) = s.p03;
s1(11) = s.p40;
s1(12) = s.p31;
s1(13) = s.p22;
s1(14) = s.p04;
s1(15) = s.p50;
s1(16) = s.p41;
s1(17) = s.p32;
s1(18) = s.p23;
s1(19) = s.p14;
s1(20) = s.p13;
s1(21) = s.p05;
p00 = s1(1);
p10 = s1(2);
p01 = s1(3);
p20 = s1(4);
p11 = s1(5);
p02 = s1(6);
p30 = s1(7);
p21 = s1(8);
p12 = s1(9);
p03 = s1(10);
p40 = s1(11);
p31 = s1(12);
p22 = s1(13);
p04 = s1(14);
p50 = s1(15);
p41 = s1(16);
p32 = s1(17);
p23 = s1(18);
p14 = s1(19);
p13 = s1(20);
p05 = s1(21);
clear x y z t
syms x y z t
eq1 = z == p00 + p10*x + p01*y + p20*x.^2 + p11*x.*y + p02*y.^2 + p30*x.^3 + p21*x.^2*y + p12*x.*y.^2 +p03*y.^3 +p40*x.^4 +p31*x.^3*y+ p22*x.^2*y.^2 + p13*x.*y.^3 + p04*y.^4 + p50*x.^5 + p41*x.^4*y + p32*x.^3*y.^2 + p23*x.^2*y.^3 + p14*x.*y.^4 + p05*y.^5;
v = -1*p2 + p1 ;
po = p1;
eq2 = x == po(1) + v(1)*t;
eq3 = y == po(2) + v(2)*t;
eq4 = z == po(3) + v(3)*t;
[x, y, z, t] = solve([eq1,eq2,eq3,eq4],[x,y,z,t]);
11 commentaires
Walter Roberson
le 30 Jan 2018
Sorry, my boundary between volunteering and paid work is that for my volunteer work I only answer public questions and give public answers; if an NDA is required then that falls outside of my volunteer sphere. That is a personal boundary; other volunteers might well have different boundaries.
I would suggest to you, though, that if you were to attach eq1, eq2, eq3, eq4 as a .mat containing symbolic variables, that people are unlikely to know what the numbers represent. This would be a bit different than if we had the original full N data that had not yet been fitted.
There are three questions for your code:
- is the fit() returning reasonable values?
- is the extraction of the parameters and creation of the four equations correct given a set of fitting parameters?
- is solve() returning correct values for the equations.
Your use of the coefficients in eq1 appears to be consistent with the names of the parameters returned by fit(). I would suggest, though, that it would be less error prone to skip the s1 vector and the p* variables and instead directly use
eq1 = z == s.p00 + s.p10*x + s.p01*y + s.p20*x.^2 + s.p11*x.*y + s.p02*y.^2 + s.p30*x.^3 + s.p21*x.^2*y + s.p12*x.*y.^2 + s.p03*y.^3 + s.p40*x.^4 + s.p31*x.^3*y + s.p22*x.^2*y.^2 + s.p13*x.*y.^3 + s.p04*y.^4 + s.p50*x.^5 + s.p41*x.^4*y + s.p32*x.^3*y.^2 + s.p23*x.^2*y.^3 + s.p14*x.*y.^4 + s.p05*y.^5;
John D'Errico
le 30 Jan 2018
I have a good reason for asking to see the data, as well as the polynomial, because I think that polynomial is very likely totally inappropriate to be fit here. And while that is only a guess, I think it to be a good one.
I don't think you can offer enough to get me interested in a consulting contract either. Anyway, Answers is not a place where you post a request for someone to perform private consulting, so advertising as if it is a bulletin board.
So I'd suggest that you contact your local university stats department, and find someone willing to work on your terms, IF you can.
Your question is virtually impossible to answer as it is though, without seeing your data. That is especially true since I'll bet I know what you are doing, and why I think there is a problem in the fit.
Réponses (1)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!