現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
solve system of matrices
2 ビュー (過去 30 日間)
古いコメントを表示
Hajar Alshaikh
2023 年 2 月 17 日
% I want to solve this system
f'(A,B)*[dA dB]'=[g(C))+B B*A-eye(n-1)]'
but when I found the derivative of f in the left side, I found that
f'(A,B)*[dA dB]'= [g(dA))-dB A*dB+B*dA]'
where A,B are (n-1)×(n-1) matrices
and C is n×n matrices
and I define a function chi from (n-1)×(n-1) matrices to the n×n matrices as
function chi= g(X)
chi= 3*trace X;
end
I want to solve this system for dA and dB
the problem for me is in the derivative part here
f'(A,B)*[dA dB]'= [g(dA))-dB A*dB+B*dA]'
can I said
[g(dA))-dB A*dB+B*dA]'= [g -eye(n-1);B A]*[dA dB]'
if not can I solve this system for dA and dB if i write it as
[g(dA)-dB A*dB+B*dA]'=[g(C)+B B*A-eye(n-1)]'
9 件のコメント
Torsten
2023 年 2 月 17 日
As far as I understand your question, you want - given A, B and C - determine dA and dB both matrices of size
(n-1) x (n-1) such that
[g(dA)-dB A*dB+B*dA]'=[g(C)+B B*A-eye(n-1)]'
where g is defined as
g(M) = 3*trace(M)
A,B are matrices of size (n-1) x (n-1) and C is a matrix of size n x n.
Is this correct ?
Hajar Alshaikh
2023 年 2 月 17 日
Yes it is correct except that C is n-1×n-1 matrix I wrote the size of C as n×n by mistake
Torsten
2023 年 2 月 17 日
Then transform your matrix equation to the form
M*x = b
by using MATLAB's "equationsToMatrix" and solve for the unknown matrices dA and dB using
x = M\b.
Hajar Alshaikh
2023 年 2 月 17 日
this way is not working because we deal here with matrices and in your way the variables have to be x and b are vectors
Torsten
2023 年 2 月 18 日
The matrix equation you have is in reality a linear system of equations in the matrix entries of dA and dB.
"equationsToMatrix" transforms your matrix equation to this underlying linear system.
After getting the solution x of this linear system, you will have to reshape it back to get the matrices dA and dB.
Hajar Alshaikh
2023 年 2 月 18 日
I read the examples about "equationsToMatrix" and all deal with b as vector and in my situation the problem is that all A, x, and b are matrices and the other problem is that I cannot seprate the component in x than the matrix A .
I mean than we cannot say
[g(dA))-dB A*dB+B*dA]'= [g -eye(n-1);B A]*[dA dB]'
Torsten
2023 年 2 月 18 日
編集済み: Torsten
2023 年 2 月 19 日
So this is not what you want ?
rng("default")
n = 20;
A = rand(n-1);
B = rand(n-1);
C = rand(n-1);
dA = sym('dA',[n-1 n-1],'real');
dB = sym('dB',[n-1 n-1],'real');
eqn = [3*trace(dA)-dB A*dB+B*dA]'==[3*trace(C)+B B*A-eye(n-1)]';
eqn = eqn(:);
vars = [reshape(dA.',[(n-1)^2 1]);reshape(dB.',[(n-1)^2 1])];
[M,b] = equationsToMatrix(eqn,vars);
sol = double(M\b);
dA = reshape(sol(1:(n-1)^2),[n-1 n-1]).';
dB = reshape(sol((n-1)^2+1:2*(n-1)^2),[n-1 n-1]).';
[3*trace(dA)-dB A*dB+B*dA]'-[3*trace(C)+B B*A-eye(n-1)]'
ans = 38×19
1.0e-14 *
-0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553
-0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553
-0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553
-0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553
-0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553
-0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553
-0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553
-0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553
-0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553
-0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553 -0.3553
Hajar Alshaikh
2023 年 2 月 18 日
first of all I really want to thank you about your help and i appritiate your time, I learend from you many functions that I dont know about them before.
Now I tried your way, but I got this error
Warning: Solution does not exist because the system is inconsistent.
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
採用された回答
Torsten
2023 年 2 月 19 日
Should be faster than the symbolic solution.
rng("default")
n = 50;
A = rand(n-1);
B = rand(n-1);
C = rand(n-1);
x0 = zeros(2*(n-1)^2,1);
x = fsolve(@(x)fun(x,A,B,C,n),x0);
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the value of the function tolerance, and
the problem appears regular as measured by the gradient.
dA = reshape(x(1:(n-1)^2),[n-1,n-1])
dA = 49×49
1.0e+03 *
-0.9697 -1.2841 -1.1100 -1.0445 -1.1586 -1.2281 -1.0768 -0.9605 -1.0724 -1.0369 -1.1764 -0.9773 -0.9512 -1.0230 -1.1881 -0.9808 -1.0192 -1.0678 -1.2432 -1.0212 -1.0383 -0.9359 -0.9486 -1.1359 -1.0584 -1.1338 -1.1257 -0.9812 -0.9628 -0.9208
-0.5211 -0.6925 -0.5981 -0.5635 -0.6226 -0.6578 -0.5814 -0.5162 -0.5780 -0.5564 -0.6303 -0.5278 -0.5112 -0.5491 -0.6402 -0.5259 -0.5471 -0.5732 -0.6705 -0.5500 -0.5594 -0.5001 -0.5119 -0.6114 -0.5700 -0.6076 -0.6053 -0.5272 -0.5172 -0.4967
0.2252 0.2944 0.2581 0.2441 0.2652 0.2793 0.2498 0.2234 0.2489 0.2389 0.2685 0.2307 0.2179 0.2377 0.2720 0.2269 0.2369 0.2441 0.2848 0.2372 0.2407 0.2138 0.2232 0.2611 0.2435 0.2586 0.2588 0.2268 0.2248 0.2153
0.2900 0.3845 0.3341 0.3153 0.3454 0.3672 0.3232 0.2882 0.3204 0.3103 0.3511 0.2943 0.2830 0.3059 0.3565 0.2920 0.3050 0.3196 0.3719 0.3056 0.3105 0.2781 0.2845 0.3404 0.3153 0.3384 0.3377 0.2935 0.2883 0.2761
0.9613 1.2734 1.1008 1.0342 1.1489 1.2161 1.0665 0.9516 1.0624 1.0265 1.1667 0.9681 0.9430 1.0141 1.1791 0.9709 1.0102 1.0580 1.2321 1.0116 1.0289 0.9269 0.9393 1.1246 1.0487 1.1223 1.1157 0.9738 0.9525 0.9124
0.4635 0.6062 0.5273 0.4976 0.5500 0.5843 0.5120 0.4595 0.5122 0.4952 0.5603 0.4662 0.4534 0.4860 0.5625 0.4661 0.4895 0.5086 0.5910 0.4872 0.4929 0.4485 0.4539 0.5406 0.5028 0.5393 0.5354 0.4676 0.4623 0.4404
0.3057 0.4060 0.3501 0.3310 0.3651 0.3872 0.3408 0.3036 0.3384 0.3259 0.3707 0.3096 0.3003 0.3228 0.3775 0.3085 0.3202 0.3362 0.3932 0.3226 0.3280 0.2935 0.2991 0.3589 0.3339 0.3559 0.3557 0.3093 0.3034 0.2922
0.6562 0.8683 0.7499 0.7020 0.7852 0.8329 0.7274 0.6510 0.7249 0.7032 0.8006 0.6565 0.6466 0.6907 0.8043 0.6631 0.6925 0.7231 0.8428 0.6889 0.7014 0.6374 0.6407 0.7674 0.7176 0.7690 0.7614 0.6654 0.6508 0.6224
1.4197 1.8876 1.6310 1.5331 1.6967 1.7968 1.5786 1.4065 1.5696 1.5174 1.7234 1.4345 1.3923 1.5008 1.7445 1.4359 1.4941 1.5624 1.8221 1.4944 1.5230 1.3674 1.3917 1.6608 1.5518 1.6598 1.6481 1.4376 1.4084 1.3491
-0.3479 -0.4612 -0.3958 -0.3722 -0.4170 -0.4424 -0.3865 -0.3433 -0.3847 -0.3716 -0.4258 -0.3469 -0.3432 -0.3660 -0.4280 -0.3510 -0.3667 -0.3843 -0.4484 -0.3650 -0.3720 -0.3375 -0.3386 -0.4079 -0.3806 -0.4080 -0.4035 -0.3528 -0.3436 -0.3303
dB = reshape(x((n-1)^2+1:2*(n-1)^2),[n-1,n-1])
dB = 49×49
-0.7671 -1.4794 -1.1889 -0.6632 -0.6091 -0.9174 -0.9572 -0.8564 -1.2919 -1.5003 -1.4821 -1.1780 -1.2001 -1.4399 -0.9749 -1.0941 -1.3005 -1.1523 -1.2406 -0.8458 -0.8755 -1.2904 -1.1953 -0.7815 -1.1088 -0.8290 -0.7059 -1.4871 -1.0271 -0.7387
-0.7014 -0.9972 -1.4334 -0.6450 -1.4131 -0.8650 -1.0542 -0.9570 -0.8857 -1.1241 -1.2580 -0.6627 -1.5752 -1.0206 -1.0571 -0.5852 -1.2458 -1.4416 -1.3939 -1.4102 -0.7027 -1.0503 -0.7914 -1.5710 -0.5791 -0.6178 -0.8306 -1.5393 -0.8213 -1.0100
-1.3987 -0.9358 -1.2485 -1.4661 -1.4134 -0.7486 -1.4896 -1.4423 -1.2488 -1.0516 -0.9565 -1.5000 -1.0950 -1.1257 -1.1427 -1.2666 -0.7565 -0.7762 -1.3715 -1.5730 -0.9660 -1.2863 -1.2233 -0.6713 -1.4615 -0.8110 -1.4616 -1.1483 -1.4464 -1.0828
-1.2156 -1.0667 -1.1013 -0.8108 -0.6275 -0.9769 -0.5925 -0.9976 -1.2301 -1.0742 -1.2096 -0.6313 -1.5682 -1.1445 -1.0673 -1.5237 -1.1282 -1.2501 -1.0468 -1.2274 -1.3954 -1.5357 -0.9583 -1.2283 -0.9820 -0.9388 -0.7739 -1.1405 -1.1063 -0.9530
-0.5938 -0.8336 -0.8765 -1.4393 -1.1236 -1.2753 -0.7344 -0.8175 -1.1087 -0.8866 -0.8209 -1.1047 -0.8042 -1.2581 -0.8475 -1.4512 -1.5375 -1.4795 -0.8872 -1.2816 -1.5588 -1.0834 -0.6814 -0.7928 -0.8789 -1.2111 -0.6990 -0.7543 -1.4918 -1.0580
-1.4736 -1.5068 -1.2816 -1.2894 -1.5208 -0.7813 -1.0492 -1.1753 -1.2928 -1.5285 -1.1491 -0.6965 -0.9757 -0.9490 -1.5674 -0.6909 -1.1737 -0.7768 -1.2652 -1.5100 -1.4397 -0.8827 -0.9552 -0.8215 -1.5282 -1.5638 -1.1214 -1.0913 -1.5516 -0.9201
-1.0930 -1.0444 -0.9593 -1.4505 -0.8991 -1.2440 -1.1207 -1.0571 -1.0825 -1.5597 -1.5594 -0.9578 -1.2742 -0.6559 -0.7613 -0.9322 -1.3862 -0.8759 -1.5645 -1.2653 -0.6615 -1.3675 -0.8405 -0.9174 -1.0383 -0.7848 -0.8923 -1.1261 -1.1631 -1.3548
-1.1222 -0.8317 -1.1453 -1.5157 -1.3841 -1.0207 -0.6374 -1.4762 -1.0657 -1.0912 -1.4273 -1.3905 -0.6423 -1.0340 -1.4393 -0.8196 -1.5622 -1.0742 -1.3476 -1.1460 -0.9154 -0.8141 -0.8190 -0.7755 -0.8653 -1.3347 -0.9597 -0.7429 -0.6966 -0.9616
-1.1841 -1.0089 -1.4655 -0.7174 -1.1791 -1.0110 -1.2357 -1.5124 -1.0755 -1.5703 -0.8611 -0.8218 -1.3253 -0.6255 -0.6103 -1.1380 -1.4636 -1.4676 -1.4072 -0.9585 -0.8138 -0.8120 -1.2006 -1.0845 -0.6623 -1.4640 -1.3692 -1.0716 -1.5042 -1.2892
-1.3381 -1.2802 -1.4206 -0.9716 -1.3673 -0.7529 -1.4673 -1.3956 -1.5136 -1.0335 -1.2601 -1.4621 -0.9981 -1.3159 -0.9096 -1.1904 -0.7915 -1.0791 -1.2837 -1.2122 -0.8955 -1.0424 -1.1006 -1.5284 -1.1598 -1.0499 -1.4168 -1.1128 -1.1712 -1.0586
[3*trace(dA)-dB A*dB+B*dA]'-[3*trace(C)+B B*A-eye(n-1)]'
ans = 98×49
1.0e-10 *
0.2774 0.2773 0.2773 0.2773 0.2774 0.2774 0.2774 0.2773 0.2774 0.2774 0.2773 0.2773 0.2773 0.2774 0.2774 0.2774 0.2774 0.2774 0.2774 0.2774 0.2773 0.2773 0.2773 0.2773 0.2773 0.2773 0.2773 0.2773 0.2774 0.2774
0.2774 0.2774 0.2774 0.2773 0.2774 0.2773 0.2774 0.2774 0.2773 0.2773 0.2774 0.2774 0.2774 0.2773 0.2773 0.2773 0.2774 0.2774 0.2773 0.2773 0.2774 0.2773 0.2773 0.2774 0.2773 0.2774 0.2774 0.2773 0.2774 0.2774
0.2774 0.2774 0.2773 0.2774 0.2773 0.2774 0.2773 0.2774 0.2773 0.2774 0.2773 0.2774 0.2773 0.2774 0.2774 0.2774 0.2774 0.2774 0.2774 0.2774 0.2773 0.2773 0.2774 0.2774 0.2774 0.2774 0.2773 0.2773 0.2774 0.2774
0.2774 0.2773 0.2774 0.2774 0.2774 0.2773 0.2774 0.2773 0.2773 0.2773 0.2773 0.2774 0.2774 0.2773 0.2774 0.2773 0.2774 0.2774 0.2774 0.2774 0.2773 0.2773 0.2774 0.2774 0.2774 0.2774 0.2774 0.2773 0.2773 0.2774
0.2773 0.2774 0.2774 0.2774 0.2773 0.2774 0.2773 0.2773 0.2774 0.2774 0.2774 0.2774 0.2773 0.2774 0.2773 0.2773 0.2773 0.2774 0.2774 0.2773 0.2773 0.2775 0.2773 0.2773 0.2774 0.2774 0.2773 0.2773 0.2773 0.2774
0.2773 0.2773 0.2773 0.2774 0.2774 0.2773 0.2774 0.2773 0.2773 0.2773 0.2774 0.2774 0.2774 0.2774 0.2774 0.2773 0.2773 0.2774 0.2774 0.2773 0.2773 0.2774 0.2774 0.2774 0.2773 0.2774 0.2774 0.2774 0.2773 0.2774
0.2774 0.2773 0.2774 0.2774 0.2774 0.2773 0.2774 0.2774 0.2774 0.2774 0.2774 0.2774 0.2774 0.2773 0.2774 0.2774 0.2774 0.2773 0.2774 0.2774 0.2773 0.2774 0.2774 0.2774 0.2774 0.2774 0.2773 0.2773 0.2774 0.2773
0.2774 0.2774 0.2774 0.2773 0.2773 0.2773 0.2774 0.2774 0.2773 0.2773 0.2773 0.2774 0.2774 0.2773 0.2773 0.2774 0.2774 0.2774 0.2773 0.2774 0.2773 0.2773 0.2774 0.2774 0.2773 0.2773 0.2774 0.2774 0.2774 0.2774
0.2773 0.2774 0.2774 0.2774 0.2774 0.2773 0.2774 0.2774 0.2773 0.2773 0.2773 0.2774 0.2774 0.2774 0.2774 0.2773 0.2773 0.2774 0.2774 0.2774 0.2773 0.2773 0.2774 0.2773 0.2774 0.2774 0.2773 0.2773 0.2774 0.2773
0.2774 0.2773 0.2774 0.2774 0.2774 0.2774 0.2773 0.2773 0.2774 0.2773 0.2773 0.2774 0.2774 0.2774 0.2774 0.2773 0.2774 0.2774 0.2773 0.2774 0.2773 0.2774 0.2774 0.2773 0.2775 0.2774 0.2774 0.2773 0.2773 0.2774
function res = fun(x,A,B,C,n)
dA = reshape(x(1:(n-1)^2),[n-1,n-1]);
dB = reshape(x((n-1)^2+1:2*(n-1)^2),[n-1,n-1]);
res = [3*trace(dA)-dB A*dB+B*dA]' - [3*trace(C)+B B*A-eye(n-1)]';
res = res(:);
end
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)