Setting up a system of linear equations in matlab

半世苍凉 提交于 2019-12-23 05:46:53

问题


I have the following equation that I want to solve:

H*b0 = M(Q+1)b(Q+1)+l+M'B

The unknowns are b0, b(q+1) and B. The sizes of the known matrices are:

H=(42 x 42)

M(Q+1) = (42 x 21-P)

l = (42 x 1)

M' = (42 x 4)

So I want to figure out how to find the vectors.

Is there a built in command that I could do to do this?

This comes from This paper

EDIT:: Size of unknowns should be (all are column vectors):

b0 = 21
b(q+1) = 21-P (P=4 in this case)
B = P (4 in this case)

回答1:


First, rearrange your equation:

H b0 - M(Q+1) B(Q+1) - M' B = l

Now, you can concatenate variables. You will end up with an unknown vector (X) of size 42 + 21 + 4 = 67. And a coefficient matrix (A) of size 42 x 67

X = [b0;  B(Q+1);  B ];   % <- don't need to execute this; just shows alignment
A = [ H, -M(Q+1), -M'];

Now you have an equation of the form:

A X = l

Now you can solve this in a least-squares sense with the \ operator:

X = A \ l

This X can be turned back into b0, B(Q+1), and B using the identity above in reverse:

b0 = X(1:42);
B(Q+1) = X(43:63);
B = X(64:67);



回答2:


As is, the problem certainly has too many degrees of freedom. Of course you have some constraints, but without knowing what kind of constrains you have I cannot really know which solution to suggest.

Suppose you only have upper and lower bounds on b(Q+1) and knew b0 is 1 everywhere, the problem would reduce to a constrained linear least squares problem.

There is a function in Matlab that can do that for you: http://www.mathworks.nl/help/optim/ug/lsqlin.html

There are mulltiple possible ways to call this function, I think the simplest one that can still do the trick for you is this:

x = lsqlin(C,d,A,b,Aeq,beq,lb,ub)

I am not an expert in this field, but if you can think of a trick to write your problem in this form, it would certainly be the easiest solution.


For practical purposes: if you cannot find a way to solve this complicated problem, perhaps try fixing b0 to some reasonable values in order to get a decent solution.




回答3:


Your problem can have a lot of solutions ; indeed you have :

42 coefficients for b0 21 coefficients for B(q+1) 21 coefficients for B

You only have 42 equations for a total of 84 coefficients !

Your problem has to be refined, with additional constraints. Once you have enough constraints, you should be able to use linear least squares in order to find out your coefficients.

for 42 constraints and variables, you don't need a function, matrix manipulations are enough. You want to find the vector X such as H*X = Y

An estimation of X is (H'*H)^-1*H'*Y.

So in Matlab :

X ~ (H'*H)\H'*Y

Don't forget to check that H'H is well conditioned and positive definite.

So all you have to do is concatenate your 3 vector coefficients in X, put your constraint coefficients in H and Y, use the formula.

Cheers



来源:https://stackoverflow.com/questions/17952905/setting-up-a-system-of-linear-equations-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!