System of equations { parametic & using 5 polynomial solve } not working

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 comentarios

Please expand on how it does not work.
When I create a random array N, and created arbitrary P1 and P2 vectors of 3 coordinates, then the outputs I got were roots of a quintic. The particular coordinates I used happened to have only one real root for the quintic. When I substituted back the real-valued roots into the equations all four of them evaluate as true.
It outputs 5 variables and does not solve for a real value which is possible when it is plotted
It does not output 5 variables: it outputs 5 roots for each variable. If you want the real root, then select the entry for which the imaginary component is 0.
That still doesn't help. I've tried the 'Real',true parameter and it does not return. All variables are returning as imaginary and incorrect.
Please attach your N values and indicate your P1 and P2
John D'Errico
John D'Errico el 30 de En. de 2018
Editada: John D'Errico el 30 de En. de 2018
If you seriously want help, the only way is if you provide all of the information as a .mat file. That way, someone (me, or Walter, or someone else who is willing to invest a fair amount of time to look at what you are doing) can take the equations you have and do the analysis themselves, looking carefully to see if you have made a mistake.
Code as you are writing it is terribly easy to make a mistake. You copy the values of those coefficients several times, into named, numbered variables. (Sorry, but that is a really bad programming style, because it is incredibly easy to make a mistake in typing.) The point is, someone needs to check everything you have done, and to do it with your variables. Is, for example, the problem simply that no intersection exists?
So attach a .mat file, containing ALL of the necessary information. This will include the fitted polynomial from fit. It will include the vectors p1 and p2.
You might include the data itself, so we could conclude if you made a reasonable choice in the polynomial that you did fit. Very often, people make silly choices in polynomial models, fitting them to data that has no chance of providing a reasonable fit. Thus, it is entirely possible that the fit itself is useless to work with, which is why your solve might produce garbage.
Can I email you the files?
You can zip them and attach the zip here.
Suzie Oman
Suzie Oman el 30 de En. de 2018
Editada: Suzie Oman el 30 de En. de 2018
They are proprietary for my work / confidential. If I can send / an NDA so it is confidential that would be great.
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:
  1. is the fit() returning reasonable values?
  2. is the extraction of the parameters and creation of the four equations correct given a set of fitting parameters?
  3. 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;
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.

Iniciar sesión para comentar.

Respuestas (1)

Suzie Oman
Suzie Oman el 30 de En. de 2018
Thanks. I will follow-up this evening with a subset of the data. That should be fine. I apologize. Just trying to do the right thing.
Best, Rosie

Etiquetas

Preguntada:

el 30 de En. de 2018

Comentada:

el 30 de En. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by