Iteratively defining and solving equations

조회 수: 10 (최근 30일)
AA
AA 2021년 12월 10일
답변: John D'Errico 2021년 12월 10일
Ok so basically I want to solve k4 = [a,b,c,d,....,] (<-M variables) for a system of M equations that go something like this:
k4(1) = k4(2)-2k4(1)+k4(M)
k4(2) = k4(3)-2k4(2)+k4(1)
.
.
.
k4(M-1) = k4(M)-2k4(M-1)+k4(M-2)
k4(M) = k4(1)-2k4(M-1)+k4(M-2)
I am not quite sure how to go about defining each of the variables and then soving the set of M equations so that I can get a numerical solution for each element of k4. I assume I'd need a for loop but I don't know how to go about it?
  댓글 수: 3
AA
AA 2021년 12월 10일
M is arbitrary but it will be a large number like 100. The size of k4 is also M. This is the simpler version of the equation I want to solve. Essentially I want a way to find solutions for a,b,c..... from this set of equations but I can't write them all out because M is large
Also I noticed a typo for k4(0) - I've changed it now to k4(1)
James Tursa
James Tursa 2021년 12월 10일
So it is going to boil down to whether your MxM system of equations is full rank or not. If it is full rank then the unique solution is k4 = 0 all elements. If not full rank then you will have other solutions. Just write everything on the left hand side with 0's on the right hand side, figure out the matrix of coefficients, and go from there. Is that last equation correct? It doesn't fit the pattern.

댓글을 달려면 로그인하십시오.

답변 (1개)

John D'Errico
John D'Errico 2021년 12월 10일
It is a LINEAR system of equations. You don't want to be solving them iteratively. You need to learn how to define the matrix that describes that system. Anyway, I'm not positive about the coefficients of your system. But it apears there are no constant terms in the problem. But your question is not very clear, so there may be. ANd I'm not confident about the coefficients in your system. So it is difficult to be sure if the problem is rank deficient or not.
But if the right hand side constants are all zero, then the solution is as James says. You will solve it using null. NOT using an iterative solution.
So start by learning how to create a matrix of coefficients. If M is large, then you may need to use tools like sparse. And it LOOKs like your matrix will be a circulant matrix. In that case, you could use either the circulant matrix tool I posted on the File Exchange, or even easier, just use gallery.
M = 8;
R = [-3,1,zeros(1,M-3) , 1];
A = gallery('circul',R)
A = 8×8
-3 1 0 0 0 0 0 1 1 -3 1 0 0 0 0 0 0 1 -3 1 0 0 0 0 0 0 1 -3 1 0 0 0 0 0 0 1 -3 1 0 0 0 0 0 0 1 -3 1 0 0 0 0 0 0 1 -3 1 1 0 0 0 0 0 1 -3
It looks vageuely like this is the matrix you want. But that is just a quck glance. In that case, this matrix would have full rank. For example:
rank(A)
ans = 8
Anyway, since it is full rank, then it has NO solution, except the vector of all zeros. But again, all of this is just a guess, since I'm not sure I am reading your system of equations propeerly.

카테고리

Help CenterFile Exchange에서 Matrix Computations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by