Clear Filters
Clear Filters

solving a matrix equation

5 views (last 30 days)
Mitra Taghizadeh
Mitra Taghizadeh on 31 Jan 2023
Commented: Walter Roberson on 3 Feb 2023
Hello everyone,
I have 13 equations and 13 unknown and I am using the following code to solve this symbolic equtions. But after one day I did not get the answer yet. I wanted to just dive me any advise if there is any other method for solving these equations?!
Thanks,
clc
clear
syms thdd1 thdd2 thdd3 q1 q2 q3 xdd ydd zdd thddo1 thddo2 thddo3...
u11 u12 u13 u14 u15 u16 u17 u18 u19 u110 u111 u112 u113 u21 u22 u23 u24 u25...
u26 u27 u28 u29 u210 u211 u212 u213...
u31 u32 u33 u34 u35 u36 u37 u38 u39 u310 u311 u312 u313...
u41 u42 u43 u44 u45 u46 u47 u48 u49 u410 u411 u412 u413...
u51 u52 u53 u54 u55 u56 u57 u58 u59 u510 u511 u512 u513...
u61 u62 u63 u64 u65 u66 u67 u68 u69 u610 u611 u612 u613...
u71 u72 u73 u74 u75 u76 u77 u78 u79 u710 u711 u712 u713...
u81 u82 u83 u84 u85 u86 u87 u88 u89 u810 u811 u812 u813...
u91 u92 u93 u94 u95 u96 u97 u98 u99 u910 u911 u912 u913...
u101 u102 u103 u104 u105 u106 u107 u108 u109 u1010 u1011 u1012 u1013...
u111 u112 u113 u114 u115 u116 u117 u118 u119 u1110 u1111 u1112 u1113...
u121 u122 u123 u124 u125 u126 u127 u128 u129 u1210 u1211 u1212 u1213...
u131 u132 u133 u134 u135 u136 u137 u138 u139 u1310 u1311 u1312 u1313
Zb=[thdd1,thdd2,thdd3,q1,q2,q3,1,xdd,ydd,zdd,thddo1,thddo2,thddo3,1].';
Ub=[u11,u12,u13,u14,u15,u16,u17,u18,u19,u110,u111,u112,u113;u21,u22,u23,u24,u25,...
u26,u27,u28,u29,u210,u211,u212,u213;...
u31,u32,u33,u34,u35,u36,u37,u38,u39,u310,u311,u312,u313;...
u41,u42,u43,u44,u45,u46,u47,u48,u49,u410,u411,u412,u413;...
u51,u52,u53,u54,u55,u56,u57,u58,u59,u510,u511,u512,u513;...
u61,u62,u63,u64,u65,u66,u67,u68,u69,u610,u611,u612,u613;...
u71,u72,u73,u74,u75,u76,u77,u78,u79,u710,u711,u712,u713;...
u81,u82,u83,u84,u85,u86,u87,u88,u89,u810,u811,u812,u813;...
u91,u92,u93,u94,u95,u96,u97,u98,u99,u910,u911,u912,u913;...
u101,u102,u103,u104,u105,u106,u107,u108,u109,u1010,u1011,u1012,u1013;...
u111,u112,u113,u114,u115,u116,u117,u118,u119,u1110,u1111,u1112,u1113;...
u121,u122,u123,u124,u125,u126,u127,u128,u129,u1210,u1211,u1212,u1213;...
u131,u132,u133,u134,u135,u136,u137,u138,u139,u1310,u1311,u1312,u1313];
uu=[Ub,-eye(13)];
uuu=uu([1:end],[4,5,6,10,11,12,13,14,15,16,17,18,19,26])
uuu = 
eqn=uuu*Zb==[0,0,0,0,0,0,0,0,0,0,0,0,0]'
eqn = 
[A,b] = equationsToMatrix(eqn,[thdd1 thdd2 thdd3 q1 q2 q3 xdd ydd zdd thddo1 thddo2 thddo3])
A = 
b = 
%sol = A\b
%Sa = solve(eqn,[thdd1 thdd2 thdd3 q1 q2 q3 xdd ydd zdd thddo1 thddo2 thddo3]);
  3 Comments
Walter Roberson
Walter Roberson on 1 Feb 2023
I wrote some code to try to solve the problem iterative. At any one time there are several possible variables to try to solve for; the program runs several solve() in parallel, taking the one that finishes first (with a useful solution.)
After 6 iterations, 7 at most, the program is having trouble making progress.
It turns out that the solutions for ydd and zdd are very large, and although it is not so bad to compute the solutions for those, that the time required to substitute the values into the equations can get quite high.
Walter Roberson
Walter Roberson on 1 Feb 2023
After solving for thdd1 thdd2 thdd3 q1 q2 my code times out trying to solve q3 . I am re-running it with a larger timeout. Most of its execution time is in subs() steps after having isolated variables.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 2 Feb 2023
You have 13 equations that you are trying to solve for 12 variables.
tic
syms thdd1 thdd2 thdd3 q1 q2 q3 xdd ydd zdd thddo1 thddo2 thddo3...
u11 u12 u13 u14 u15 u16 u17 u18 u19 u110 u111 u112 u113 u21 u22 u23 u24 u25...
u26 u27 u28 u29 u210 u211 u212 u213...
u31 u32 u33 u34 u35 u36 u37 u38 u39 u310 u311 u312 u313...
u41 u42 u43 u44 u45 u46 u47 u48 u49 u410 u411 u412 u413...
u51 u52 u53 u54 u55 u56 u57 u58 u59 u510 u511 u512 u513...
u61 u62 u63 u64 u65 u66 u67 u68 u69 u610 u611 u612 u613...
u71 u72 u73 u74 u75 u76 u77 u78 u79 u710 u711 u712 u713...
u81 u82 u83 u84 u85 u86 u87 u88 u89 u810 u811 u812 u813...
u91 u92 u93 u94 u95 u96 u97 u98 u99 u910 u911 u912 u913...
u101 u102 u103 u104 u105 u106 u107 u108 u109 u1010 u1011 u1012 u1013...
u111 u112 u113 u114 u115 u116 u117 u118 u119 u1110 u1111 u1112 u1113...
u121 u122 u123 u124 u125 u126 u127 u128 u129 u1210 u1211 u1212 u1213...
u131 u132 u133 u134 u135 u136 u137 u138 u139 u1310 u1311 u1312 u1313
Zb=[thdd1,thdd2,thdd3,q1,q2,q3,1,xdd,ydd,zdd,thddo1,thddo2,thddo3,1].';
Ub=[u11,u12,u13,u14,u15,u16,u17,u18,u19,u110,u111,u112,u113;u21,u22,u23,u24,u25,...
u26,u27,u28,u29,u210,u211,u212,u213;...
u31,u32,u33,u34,u35,u36,u37,u38,u39,u310,u311,u312,u313;...
u41,u42,u43,u44,u45,u46,u47,u48,u49,u410,u411,u412,u413;...
u51,u52,u53,u54,u55,u56,u57,u58,u59,u510,u511,u512,u513;...
u61,u62,u63,u64,u65,u66,u67,u68,u69,u610,u611,u612,u613;...
u71,u72,u73,u74,u75,u76,u77,u78,u79,u710,u711,u712,u713;...
u81,u82,u83,u84,u85,u86,u87,u88,u89,u810,u811,u812,u813;...
u91,u92,u93,u94,u95,u96,u97,u98,u99,u910,u911,u912,u913;...
u101,u102,u103,u104,u105,u106,u107,u108,u109,u1010,u1011,u1012,u1013;...
u111,u112,u113,u114,u115,u116,u117,u118,u119,u1110,u1111,u1112,u1113;...
u121,u122,u123,u124,u125,u126,u127,u128,u129,u1210,u1211,u1212,u1213;...
u131,u132,u133,u134,u135,u136,u137,u138,u139,u1310,u1311,u1312,u1313];
uu=[Ub,-eye(13)];
uuu=uu([1:end],[4,5,6,10,11,12,13,14,15,16,17,18,19,26]);
eqn=uuu*Zb==[0,0,0,0,0,0,0,0,0,0,0,0,0]';
partial = solve(eqn(1:11), [xdd ydd zdd thddo1 thddo2 thddo3 thdd1 thdd2 thdd3 q1 q2]);
eqn2 = subs(eqn(12:end), partial);
q3_sol = solve(eqn2(1), q3);
fullsol = subs(partial, q3, q3_sol);
fullsol.q3 = q3_sol;
toc
Elapsed time is 23.067718 seconds.
Does it actually work? Well, at this point you could backsubs = subs(eqn, fullsol); but that step will take about 4 minutes. Displaying the solutions (including the substituted equations) can take a long time.
As you have fewer equations than variables, you should expect that the final equation might not balance out. But simplifying backsubs(end) will probably take about 8 minutes.
  4 Comments
Mitra Taghizadeh
Mitra Taghizadeh on 3 Feb 2023
Thanks for your answer. You said that we have 13 equations 12 unknown... If we change the last row to 0,0,0,0,0,0,0,0,0,0,0,0,1 Then it may work? I tryed to solve it but again it was taking too much time
Walter Roberson
Walter Roberson on 3 Feb 2023
[A,b] = equationsToMatrix(eqn,[thdd1 thdd2 thdd3 q1 q2 q3 xdd ydd zdd thddo1 thddo2 thddo3])
Notice that [thdd1 thdd2 thdd3 q1 q2 q3 xdd ydd zdd thddo1 thddo2 thddo3] is 12 variables. You are asking to solve for 12 variables. But you have 13 equations.
You need to either discard an equation or solve for one more variable.
I showed the solution for effectively discarding an equation, leading to the variable I named fullsol . It is unfortunately unclear what evaluating the left hand side of the final equation would give you.
u1313 + q1*u1310 + q2*u1311 + q3*u1312 + thdd1*u134 + thdd2*u135 + thdd3*u136 - 1 == 0
That is a linear transformation of expressions that are 7 to 45 megabytes each, and whatever the result, it has to exactly balance to the right hand side. It is possible to compute what the result is, but it is very slow.

Sign in to comment.

Tags

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!