how to solve matrix equation?

I want to solve a equation which has vector known elements and obvisouly the answer should be vector too.
x1=sym('x1',[121 1]);
x2=sym('x2',[121 1]);
s=solve(x1+x2==n1,x1.*x2==n2,[x1,x2]);
but I think I didn't write the right code coz it's been a long time that is busy and there is no answer yet. I really need your help.

 Accepted Answer

x1+x2=n1
x1*x2=n2
so
x2 = n1-x1
x1*(n1-x1) = n2
x1*n1-x1^2 = n2
x1^2 - x1*n1 + n2 = 0
and solve the quadratic to get x1 and then x2. There will be two solutions
Do this just for scalars to get the forms of the solutions. Then substitute in the vectors.

4 Comments

actuaaly i do this. thank you sir
there is another problem that i get the error that it couldn't convert sym to double "DOUBLE cannot convert the input expression into a double array.
and here is the code
TINV=importdata('TINV.csv');
x=sym('x',[242 2]);
s1=solve(u.*x==TINV,x);
I would really appreciate any help you might be able to give me.
I do not think that code can generate that error message.
TINV = rand(42, 2);
u = rand(42,2);
x = sym('x',[42 2]);
s1 = solve(u.*x==TINV,x);
S1 = subs(x, s1);
vpa(S1, 16)
ans = 
TINV ./ u
ans = 42×2
0.1690 2.2527 1.9319 0.0329 0.1691 0.2403 0.3203 17.3036 1.7686 3.9315 2.8071 2.5802 0.2166 23.2165 0.1956 7.5645 2.7668 0.1501 1.0861 6.2973
Under the assumption that u is numeric and that impordata is returning back a numeric array, then you can see that using plain division TINV ./ u gives the needed results.
If u is not numeric, or importdata() is not returning a numeric array, then you need to give us more details.
the thing is I have a matrix that is not square matrix[242 2]
and i want it to be inverse then i thought if A*A(inv)=1
So I create a matrix [242 2] that gives me what i want when A*A(inv) is done. then u*x=my creation would give me x that is my inverse matrix
and i ran your code and it didn't work.
format long g
A = rand(42,2);
Ainv = pinv(A);
Ainv * A
ans = 2×2
1 -5.20417042793042e-17 -1.38777878078145e-16 1
ans = 42×42
0.122279499034516 0.100591415380188 0.0828882943136175 0.00950733225267564 0.0643791627164946 -0.0495366330834786 0.0323927791469979 0.0810689532034453 0.00723859743041875 0.0614055106488573 0.0281472612408997 0.0103958103260886 0.00419121852178334 0.000443856252444105 0.0633644133018594 0.0572660502092225 -0.0254592276700414 -0.0671865361348825 0.0356470256968464 -0.0325611918191314 -0.062762560254855 0.0600155324726122 -0.00745774679471391 0.0933225155629304 -0.0677605311147749 0.0310572199058558 0.000683735860166118 0.12114679354168 0.0273682604229063 -0.0404960035255129 0.100591415380188 0.0829323704379949 0.0671784619264675 0.00686127541624179 0.051411844803746 -0.0437212376649601 0.0235735210496245 0.0659541224550693 0.00525255992838871 0.0477855609641493 0.0223442937564653 0.00568785007493196 0.000266661405490322 -0.00275641820738351 0.0510668476915052 0.0461221570017992 -0.0233792013966787 -0.058375424067824 0.028221149304995 -0.0288838344190183 -0.0548217641902133 0.0482861285754476 -0.00905003890961012 0.0758062479048013 -0.0591438163935129 0.0255235904715697 -0.00177157151383935 0.0999838350490465 0.0205094679794906 -0.0366189810000271 0.0828882943136175 0.0671784619264675 0.0617631236862641 0.0117525348413641 0.052204844907584 -0.0171503022235395 0.0389573474528528 0.0590238933310336 0.00878991265227885 0.0567151411633483 0.0235629031940631 0.0228861970008722 0.0204338581827212 0.0175638907691266 0.0488084185981191 0.0442762011716884 -0.00378854597924713 -0.0283692181141537 0.0302654782479146 -0.0104702089864427 -0.0248966716877106 0.0466810959627405 0.0110656273479028 0.0685914607665231 -0.027120218119098 0.0211916254144342 0.0133713330985715 0.0803274379804908 0.0296379518653182 -0.00917003311669867 0.00950733225267566 0.0068612754162418 0.0117525348413641 0.00579142182426778 0.0131577952624963 0.0117856837819247 0.0186992929943493 0.0101776494529567 0.00425891652240739 0.0191382461181393 0.00645554570367515 0.0158846015441607 0.0170712243185868 0.0164659664176226 0.0105008008785478 0.00964745303468412 0.0108409370383402 0.011122725974723 0.00857947126307491 0.00851118207049477 0.0119175881943944 0.0103762938028744 0.0147645364323098 0.0123309897232221 0.012637278253383 0.00254721964630818 0.0123392438508897 0.00771259317015302 0.0126800068632322 0.0142513837172234 0.0643791627164946 0.051411844803746 0.052204844907584 0.0131577952624963 0.0470495989295207 -0.000848446856654554 0.0431637625556737 0.048933993283779 0.00977510640121653 0.0555071235024547 0.02170465453138 0.0298004625932581 0.0292269507348875 0.0267474900242421 0.0423553237778054 0.0385327158721362 0.00728294633092717 -0.00899639136739272 0.0281394754193564 0.000675530135516445 -0.00593964060131988 0.0408114070136169 0.0208332575559666 0.0573227081321525 -0.00678270029309243 0.0165651680688099 0.0201848087634951 0.0610289187169428 0.0314360420362163 0.00675579920859723 -0.0495366330834786 -0.0437212376649601 -0.0171503022235395 0.0117856837819247 -0.000848446856654542 0.0684667042561843 0.0369585765492405 -0.0208499000875407 0.00850745657253676 0.0195819943012646 0.00180434722178253 0.042451493410837 0.0501308897338612 0.0506774347370917 -0.00841686763851576 -0.00712001280886565 0.0499944363637104 0.0778123331454642 0.00353511081681727 0.047369724514395 0.0774157068988091 -0.00663966601277362 0.0505138338307351 -0.0220978958293409 0.0828707081324624 -0.0121714990607543 0.0377498500728268 -0.0543601035818623 0.0215728155312605 0.0702602734308179 0.032392779146998 0.0235735210496245 0.0389573474528528 0.0186992929943493 0.0431637625556737 0.0369585765492404 0.0604030683470199 0.0338845473007653 0.013755080171894 0.0622700690426726 0.0211225684139769 0.0510388148027409 0.054740584338676 0.0527425609781959 0.0346380841191454 0.0318081338588962 0.034315556853552 0.0345547724874134 0.0280440701852602 0.0267411689613347 0.0371707960738655 0.0341860941067182 0.0471677972758245 0.0409758186369918 0.0393963011045024 0.00865163794016675 0.0395297308317907 0.0266267684629125 0.0410452507251998 0.0449991707298244 0.0810689532034453 0.0659541224550693 0.0590238933310336 0.0101776494529567 0.048933993283779 -0.0208499000875407 0.0338845473007653 0.0567184290513842 0.00763354197835819 0.0517261445507159 0.0219334466663459 0.0184540258379041 0.0156204589198864 0.0128953066778725 0.0462841300237181 0.0419502336889737 -0.00704719427071437 -0.032007466161975 0.0280872723183638 -0.0131188527015599 -0.0287286711319365 0.0441680841014552 0.00682303533499611 0.0657630391629541 -0.0311923012482871 0.0206919472594538 0.00987531724699025 0.0790091712989869 0.0262368791468966 -0.0135042844209968 0.00723859743041877 0.00525255992838872 0.00878991265227885 0.00425891652240739 0.00977510640121653 0.00850745657253676 0.013755080171894 0.00763354197835819 0.00313250949992457 0.0141434060498184 0.00478794886709362 0.0116449573116017 0.0124986981604577 0.0120472235058898 0.00782894836697883 0.0071905305986783 0.00787206267385261 0.00798157028767676 0.00635914347893124 0.00615120842490258 0.0085733230374413 0.00773010501205235 0.0107841881246033 0.00923726604119257 0.00908825921105944 0.00193542975243093 0.00902874543056264 0.0059229761790014 0.00933984492253078 0.0103322557487092 0.0614055106488573 0.0477855609641493 0.0567151411633483 0.0191382461181393 0.0555071235024547 0.0195819943012646 0.0622700690426726 0.0517261445507159 0.0141434060498184 0.0716741328870241 0.0262664810407564 0.048083841820535 0.0497132786978242 0.0469390143282528 0.0476677801980033 0.0435272585332005 0.0236646513502061 0.0127353914422157 0.0344133334554462 0.0150444371570581 0.0162389282125934 0.0463723554557685 0.0398803900221919 0.0612930167970301 0.0168800391577657 0.0159728050077307 0.0352738026206232 0.0559844775340679 0.0437441958302761 0.0291337114122371
It isn't clear what you mean when you say that you want A * Ainv = 1 for a non-square matrix. Do you mean a matrix with all ones? Do you mean a non-square matrix in which the main diagonal is 1 and the rest is 0? What size do you expect A*Ainv to be?

Sign in to comment.

More Answers (1)

Nara Lee
Nara Lee on 24 Apr 2021
assume that I have S11[121 1],S21 [121 1] ,S12[121 1],S22[121 1] ,and S=[S11 S12;S21 S22] So S would be S[242 2]
THEN I thought if for example S11*invS11=1 , S12*inv(S12)=0 , S21*inv(S21)=1, S22*inv(S22)=0 but in form of TINV=[242 2]

Categories

Asked:

on 18 Apr 2021

Answered:

on 24 Apr 2021

Community Treasure Hunt

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

Start Hunting!