# Least squares fit of a symmetric linear system

I have $$q$$ measurements with $$p$$ different excitations.

In one special case, they might be equal in length. For example, I might have 12 measurements ($$q=12$$) with three excitations each ($$p = 3$$), like so:

a0 = {1, 2, 3}
a1 = {0, 4, 1}
a2 = {4, 4, 4}
a3 = {2, 1, 1}
....
a11 = {3, 1, 5}


which results in 12 different observations/measurements — in this case also with three elements each (q = 3):

b0 = {17, 22, 10}
b1 = {21, 19, 13}
b2 = {40, 48, 20}
b3 = {14, 17, 6}
....
b11 = {22, 34, 11}


I would like to know the p x q (in this case 3 x 3) matrix Xfits best with least squares fit.

$$\qquad b_n==X\cdot a_n$$ for $$n=0\dots11$$

Is there's a simple way to get this estimation in Mathematica?

I also have some additional knowledge of the matrix. The elements satisfy

X[[i, j]] == X[[j, i]]


Is there is a way to make the least square fit aware of the symmetry?

I think this is some sort of multivariate regression, but I don't get the right starting point.

• I think you are looking for LeastSquares. Apr 5, 2019 at 21:40
• MarcoB, thank you for the hint. LeastSquare does the job. However - it can not handle the knowledge of equal coefficients. Apr 7, 2019 at 6:00

One possibility is to state this as a minimization problem:

a = RandomInteger[{0, 10}, {3, 11}];
b = RandomInteger[{0, 10}, {3, 11}];
xSym = {{x[1, 1], x[1, 2], x[1, 3]}, {x[1, 2], x[2, 2],
x[2, 3]}, {x[1, 3], x[2, 3], x[3, 3]}};
Minimize[Norm[b - xSym.a, "Frobenius"], Union[Flatten[xSym]]] // N


Here a and b are your data matrices, xSym is the symmetric 3 by 3 unknown, and the final line minimizes the norm of b - xSym.a. You could also use other norms:

NMinimize[Norm[b - xSym.a, 2], Union[Flatten[xSym]]]


or

NMinimize[Norm[b - xSym.a, 1], Union[Flatten[xSym]]]

• Thank you. Works exactly as indented. Apr 7, 2019 at 5:58
{"ft_lang_label":"__label__en","ft_lang_prob":0.8941837,"math_prob":0.99947613,"size":980,"snap":"2022-40-2023-06","text_gpt3_token_len":339,"char_repetition_ratio":0.09631147,"word_repetition_ratio":0.0,"special_character_ratio":0.39183673,"punctuation_ratio":0.19130434,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99936086,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-10-04T19:39:06Z\",\"WARC-Record-ID\":\"<urn:uuid:7f57d976-bab7-446d-8ada-d285bedd83ae>\",\"Content-Length\":\"229361\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:46d959c0-b252-4346-b420-3d7ac9cce9f7>\",\"WARC-Concurrent-To\":\"<urn:uuid:b1ac8ee9-c998-497e-81e9-acef43c1e5b3>\",\"WARC-IP-Address\":\"151.101.129.69\",\"WARC-Target-URI\":\"https://mathematica.stackexchange.com/questions/194699/least-squares-fit-of-a-symmetric-linear-system\",\"WARC-Payload-Digest\":\"sha1:LSDRAFZTBSIRTMGAOUUZW3BECNHTGIIT\",\"WARC-Block-Digest\":\"sha1:3XYTAWUPRHZBXDUPB7LOK6XERF6DNRTH\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-40/CC-MAIN-2022-40_segments_1664030337524.47_warc_CC-MAIN-20221004184523-20221004214523-00206.warc.gz\"}"}