Generalised solution to a n-order system of equations
Mostrar comentarios más antiguos
I want to solve (for the first term) of a system of n-1 equations, in terms of n. How should I do it?
Essentially I want to solve for a_1 in terms of n:
(This holds for all k=1,...,n-1).
For example, with n=4, I have these 3 equations I would like to solve:
.Once can check that
satifies this set of equations. In my example, I only want
.
As a more general example, this is the set of (n-1) equations:

I can write the code to solve for specific n, (like n=4 above). However, I would like to have a general formula in terms of n.
How do I code this in MatLab? I always meet a lot of errors complaining about the general formula. Thank you.
7 comentarios
John D'Errico
el 11 de Sept. de 2024
Editada: John D'Errico
el 11 de Sept. de 2024
While you said "essentially", you are not giving any essential information. Even as a mathematician myself, I do not follow what you are asking.
For example, it seems like you are talking about a system of n equations (or maybe only n-1 equations), with unknowns a_1,..., a_n. The sum goes from 1 to the smaller of n-1 or 2*k, whichever is smaller. But k seems to vary from 1 to n. Confusing even so far.
Please give a simple example. Perhaps with n = 4. Write it out CLEARLY, so someone can help you. Don't write it in terms of sums. WRITE OUT THE ACTUAL EQUATIONS YOU NEED TO SOLVE! Give someone an example, a pattern we can follow and understand.
If you cannot do that, explaining what you need to someone else, how can you or anyone possibly write code to do what has no explanation? (I would suggest this is your problem. Perhaps you do understand what you need to do, we do not know that is true or not. But I think you have only an expression there, that you are then hoping to write directly into MATLAB code using sums, etc., and have a magical solution appear.)
Do this as a comment on your question, or by editing your question to add that information.
David Goodmanson
el 12 de Sept. de 2024
Editada: David Goodmanson
el 12 de Sept. de 2024
Hi Aden, this seems to be defined adequately (I'm assuming that 2k on the right hand side is part of the summation), is it a homework problem?
Aden
el 12 de Sept. de 2024
John D'Errico
el 12 de Sept. de 2024
Thank you for your clarification. It was not at all clear what you meant at first, but I see your question now. It is actually an interesting one, IMHO, that gets into the linear algebra of how you solve such a question.
I'll post an answer now, first, in terms of how I would solve it for specific n, and then look to see how we might generalize it for any n.
Respuesta aceptada
Más respuestas (2)
John D'Errico
el 12 de Sept. de 2024
Editada: John D'Errico
el 12 de Sept. de 2024
(Edited to fix my error in extrapolating your equation system. I had not seen at first you were essentially adding two terms to each equation for increasing k.)
For ANY value of n, you have n-1 unknowns, and n-1 equations. But all you want to do is to compute a_1, disregarding the other unknowns. And that would seem reasonable. Well, maybe possible.
I can create the problem in matrix form, as such:
function [A,b] = Ab(N)
[K,J] = ndgrid(1:N-1);
A = diag(2*(1:(N-1))) - (2*K >= J);
b = 2*(1:(N-1))';
end
As you can see, I combined all terms into one matrix A.
[A,b] = Ab(4)
The complete solution for n==4 is then
format rat
A\b
First, we should notice that A is always full rank. Just by looking at A in general, that would seem clear, but a proof should not be impossible.
[A,b] = Ab(5)
A\b
[A,b] = Ab(6);
A\b
And that clearly works, at least for specific values of n to yield the same result you have.
One idea might be to look at the LU factors of A. Note they are quite well behaved as n grows. For example:
[A,b] = Ab(7);[L,U] = lu(A)
[A,b] = Ab(8);[L,U] = lu(A)
Noting that as n grows, it is only the last column of L and U that seem to change, I might not be surprised if one could write those factors down in some simple form. I don't see how at the moment, but it might be worth looking at. And you can recover the solution as
U\(L\b)
A nice thing about LU factors is, if you are careful, you can get the last element of the solution, knowing only L, and the last diagonal element of U. And if we flip the matrix A from left to right, which is equivalent to resequencing the unknowns in reverse order....
[L,U] = lu(fliplr(A));
C = L\b;
C(end)/U(end,end)
I hope you see where I am going. If we could write down the LU factors, in a simple way as a function of N, for the flipped (left to right) matrix A, then solving for the FIRST element of a becomes simple. All you need to know is a way to compute the factro L, as well as the last diagonal element of U. A very nice thing about this is it might also give you a way to prove the long term (linear with n) behavior of the first element of a.
2 comentarios
John D'Errico
el 12 de Sept. de 2024
Editada: John D'Errico
el 12 de Sept. de 2024
No problem. I was in a hurry, so I'll check things over. I hope perhaps my re-written answer may give you a direction to follow.
Here is my code, that provies a range of answers from a to b, inclusive.
Besides that you shouldn't give the same names to the lower bound of your range and the symbolic array a, what is your question ?
I used the below code, and it seems to give similar results as yours. The behaviour of a1 with n looks quite linear - that's why I made a linear fit at the end.
nmax = 25;
a1 = sym('a1',[nmax,1]);
for n = 1:nmax
a = sym('a',[n 1]);
for k = 1:n
ub = min(n-1,2*k);
eqn(k) = 2*k*a(k)==sum(a(1:ub))+2*k;
end
[A,b] = equationsToMatrix(eqn,a);
sol = A\b;
a1(n) = sol(1);
end
a1 = double(a1);
M = [ones(nmax,1),(1:nmax).'];
rhs = a1;
sol = M\rhs;
hold on
plot(1:nmax,a1)
plot(1:nmax,sol(1)+sol(2)*(1:nmax))
hold off
grid on
4 comentarios
I'll post an answer now, first, in terms of how I would solve it for specific n, and then look to see how we might generalize it for any n.
My question is, to find (if possible) a closed form expression of a_1 for each n. (In other words, a general solution for each n).
I don't fully understand what you mean here. I thought of a_1 as a function of n, like a_1 = 2.51778*n + sin(n^2). Or do you mean something else here ?
John D'Errico
el 12 de Sept. de 2024
Still writing. It will take an extra hour though, as my wife is asking for a boat ride. ;-) But yes, my hope is to see if a solution exists as a function of n, and possibly as a limit.
May I ask about the context in which this problem appeared ?
Is this a special field of investigation ?
Try asking the question in a pure maths forum:
Categorías
Más información sobre Linear Algebra en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




