How to find the coefficient matrix of a set of nonlinear equations?

5 visualizzazioni (ultimi 30 giorni)
I want to find the coefficient matrix (A) of the following equations:
f1 = (a+2*b+c+5*d)^3;
f2 = (3*a+b+4*c+d)^3;
f3 = (a+b+5*c+d)^3;
f4 = (a+2*b+c+6*d)^3;
The above equations can be written in the following form:
f=A(a,b,c,d)X
Which X= Transpose{a b c d}
and A is a matrix which its element are functions of a,b,c,d.
How to find such matrices in Matlab?
  6 Commenti
Torsten
Torsten il 8 Mar 2022
And it does not matter that there might be thousands of possibilities for the matrix A ?
No restrictions on the powers of the variables (a^n, b^n, c^n, d^n) within the matrix A ?
Mehdi
Mehdi il 8 Mar 2022
Modificato: Mehdi il 8 Mar 2022
No does not matter, just rational elements. My equations are something like below:
f1 = (a+2*b+c+5*d+...)^3;
f2 = (3*a+b+4*c+d+...)^3;
f3 = (a+b+5*c+d+...)^3;
f4 = (a+2*b+c+6*d+...)^3;
.
.
fn = (a+7*b+c+3*d+...)^3;
No restrictions on powers.

Accedi per commentare.

Risposte (2)

Torsten
Torsten il 10 Mar 2022
Modificato: Torsten il 11 Mar 2022
There might be more elegant solutions, but this is one way you could generalize.
I did it in octave ; maybe you will have to access the elements of subfexp by subfexp{i} instead of subfexp(i).
You will have to apply the code to all 4 functions involved - I did it for one only.
If n variables are involved, you will have to write the code for an array of coefficients (A) instead of addressing each coefficient individually (a,b,c,d).
fa, fb, fc and fd give the matrix entries in row i if f = fi.
syms a b c d
f = (a+2*b+c+5*d)^3;
fexp = expand(f);
f1 = collect(fexp,a)
subfexp = children(fexp);
subfexpa = [];
subfexpb = [];
subfexpc = [];
subfexpd = [];
for i=1:length(subfexp)
if (has(subfexp(i),a))
subfexpa = [subfexpa,subfexp(i)/a];
continue;
end
if (has(subfexp(i),b))
subfexpb = [subfexpb,subfexp(i)/b];
continue;
end
if (has(subfexp(i),c))
subfexpc = [subfexpc,subfexp(i)/c];
continue;
end
if (has(subfexp(i),d))
subfexpd = [subfexpd,subfexp(i)/d];
continue;
end
end
fa = sum( subfexpa);
fb = sum( subfexpb);
fc = sum( subfexpc);
fd = sum( subfexpd);
res = simplify(a*fa + b*fb + c*fc + d*fd - fexp);
  2 Commenti
Torsten
Torsten il 11 Mar 2022
Modificato: Torsten il 11 Mar 2022
Here is a much simpler solution (I wonder why I didn't come up with it until now):
f =
(a+2*b+c+5*d)^3 =
(a+2*b+c+5*d)*(a+2*b+c+5*d)^2 =
a*(a+2*b+c+5*d)^2 + 2*b*(a+2*b+c+5*d)^2 + c*(a+2*b+c+5*d)^2 + 5*d*(a+2*b+c+5*d)^2
So choose
fa = (a+2*b+c+5*d)^2
fb = 2*(a+2*b+c+5*d)^2
fc = (a+2*b+c+5*d)^2
fd = 5*(a+2*b+c+5*d)^2
This is easy to implement and generalize.

Accedi per commentare.


John D'Errico
John D'Errico il 11 Mar 2022
Modificato: John D'Errico il 11 Mar 2022
This is a linear problem, IF you recognize that each of the right hand sides are linear in a,b,c,d except for the cube around them.
f1 = (a+2*b+c+5*d)^3;
f2 = (3*a+b+4*c+d)^3;
f3 = (a+b+5*c+d)^3;
f4 = (a+2*b+c+6*d)^3;
If a solution exists, then we can simply choose the real cube roots of each of f1,f2,f3,f4.
So those equations reduce to:
nthroot(f1,3) = a+2*b+c+5*d;
nthroot(f2,3) = 3*a+b+4*c+d;
nthroot(f3,3) = a+b+5*c+d;
nthroot(f4,3) = a+2*b+c+6*d;
Note that the cube roots of any real number always have exactly one real solution. nthroot returns it, so this is unambiguous for the problem as stated. If f is negative, then nthroot will return the negative cube root. If f is positive, then nthroot returns the positive cube root.
The right hand sides are now entirely and purely linear in the variables a,b,c,d.
So we can solve the problem trivially as
A = [1 2 1 5;3 1 4 1;1 1 5 1;1 2 1 6];
abcd = A\nthroot([f1;f2;f3;f4],3)
This yields a vector of the UNIQUE solutions to the problem. No iterative schemes are needed. Nothing symbolic even.
As long as the matrix A is not singular, a unique solution exists. And what is the rank of A?
rank(A)
ans =
4
So A is full rank.
I'm not sure I see the difficulty here. Perhaps if those were other powers than 3 on the right hand sides. For example, had the problem been one where you were raising things to the 4th or 6th power, then you would have some ambiguity in the solution. But even then, you would merely solve for all cases, so the solution would be non-unique. And with other powers, like the 2nd or 5th or 7th powers, again, only one real root can eist. Still no substantial problem in any case.
  2 Commenti
Torsten
Torsten il 11 Mar 2022
Modificato: Torsten il 11 Mar 2022
As far as I understand, the OP just wants to write a multivariate polynomial P of the form
P(x(1),...,x(n)) = (a(1)*x(1)+a(2)*x(2)+...+a(n)*x(n))^m
depending on x(1),x(2),...,x(n) as
P = M(x(1),...,x(n))*[x(1);x(2);...,;x(n)]
where M is an n-dimensional row vector whose elements depend on x(1),...,x(n) with nonnegative powers.
Thus if
P = (x(1)+x(2))^2,
e.g.,
M = [(x(1)+x(2))^2/x(1),(x(1)+x(2))^2/x(2)]
would not be allowed, but
M = [x(1)+x(2),x(1)+x(2)]
(as suggested as solution).
John D'Errico
John D'Errico il 11 Mar 2022
I don't see how you would conclude that from the question, or even from the comments. Anything could be the case from such a confusing question.

Accedi per commentare.

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by