# System of linear equation with mixed solution

5 views (last 30 days)

Show older comments

Hi all,

Suppose I have a system of linear equations consist of 5 linear equation with 5 unknowns. I would expect one of the solution to be a real number and the other four can be a complex number---of which 2 of them are the conjugate of the other two.

I am using "linsolve" to find the solution.

But how to force linsolve so that one of the solution is restricted to be a real number?

Or, is there any other function or method available to solve the problem?

I am copying the example matrix to be solved below. System to be solved is A*X = B

A =

-2.6561 + 0i -1.1497 + 0i -0.99492 + 0i -1.1497 + 0i -0.99492 + 0i

2 + 0i 1 + 0i 1 + 0i 1 + 0i 1 + 0i

0 + 0i 0 - 1.0723i 0 - 0.99746i 0 + 1.0723i 0 + 0.99746i

0 + 0i 0 + 1.8491i 0 + 0.047561i 0 - 1.8491i 0 - 0.047561i

-0.25067 + 0i -1.7245 + 0i -0.047682 + 0i -1.7245 + 0i 0.047682 + 0i

B =

62.5

56.731

4.9963

0

0

thank you,

##### 0 Comments

### Answers (3)

John D'Errico
on 20 Nov 2017

You have a 5x5 linear system, A*x = B. The solution is unique.

Given the coefficients you have provided, I get these results:

A\B

ans =

-184.762230633461 + 0.0342461681524254i

13.4283410707132 - 0.139958213907098i

199.699389562748 + 2.61519434430493i

13.4283410707132 - 0.00745651663454558i

199.699389562748 - 2.53627195006814i

It appears you have APPROXIMATELY two complex conjugate pairs.

199.699389562748 + 2.61519434430493i

199.699389562748 - 2.53627195006814i

13.4283410707132 - 0.139958213907098i

13.4283410707132 - 0.00745651663454558i

They are not exactly so, possibly because your array A has only been provided to 5 significant digits. So I'd expect to see some slop here.

Similarly, you have one variable that is mostly real, with a small imaginary part. Again, some junk is to be expected, because you have not provided exact elements for the array A, and the right hand side.

-184.762230633461 + 0.0342461681524254i

Just wanting to have a solution that satisfies your goals is useless. Again, there is ONLY one solution to this problem. It is unique. You can strenuously demand a solution of the form you want, but all is for naught. There is only ONE solution vector to that problem. There is no way to directly require linsolve to produce a solution with the properties that you desire.

There potentially will be a perturbed matrix A and right hand side vector B, that yields a solution matching your goals. Actually, there will be infinitely many such perturbations to A and B.

So there are several ways you might try to solve this, none of which are really within the scope of this site. You might...

1. Modify the above solution minimally, so that it satisfies your goals. So adjust the real and imaginary parts of each element so they are as required. Then you could solve for a perturbed matrix Ahat = A+deltaA, such that the solution

(A + deltaA)*x = B

has the desired properties. This approach is not terribly satisfying to me, since, while probably doable, it would yield little value to you.

Better would be to recognize that your requirements for the solution are those of the roots of a polynomial. So you might want to think of how to formulate this as an eigenvalue problem.

##### 0 Comments

Torsten
on 20 Nov 2017

If you have 5 equations in 5 unknowns and linsolve does not complain that the matrix is singular, your system has a unique solution. In this case, you can't force a solution component to be a real number.

If the matrix is singular, you might have a chance.

Best wishes

Torsten.

##### 0 Comments

Bjorn Gustavsson
on 20 Nov 2017

When trying the direct equation-solving matlab-solution neither of the components of X is close to being a real number, neither are any pair of the other four close to being conjugate pairs.

X = A\B

X =

-184.76 + 0.034246i

13.428 - 0.13996i

199.7 + 2.6152i

13.428 - 0.0074565i

199.7 - 2.5363i

Obviously I had to start with the numbers you posted so there is plenty room for finite precision-errors.

What you could do is of course to write a dedicated error-function that forces the solution to be one-real-two-conjugate-pairs. Something like this:

function err = constr_real_conj_eq_err_fcn(x,A,B,idx_order)

X = [x(1);x(2)+1i*x(3);x(2)-1i*x(3);x(4)+1i*x(5);x(4)-1i*x(5)];

X = X(idx_order);

err = sum(abs(A*X-B));

Then you can use the solution from linsolve or \ to generate an initial guess for X and the permutation vector idx_order and find the solution using fminsearch or the like.

HTH

##### 1 Comment

Bjorn Gustavsson
on 20 Nov 2017

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!