Solve an algebraic matrix equation

1 回表示 (過去 30 日間)
Vincent Ike
Vincent Ike 2021 年 7 月 13 日
コメント済み: Vincent Ike 2021 年 7 月 16 日
Please I need help to obtain the variables (U, V, W, Th) as the solution of the matrix algebra equation below, say
syms U V W Th
a24 = 0:0.2:5; % which is a step forcing function (in time)
F = rand(4,4)*[U; V; W; Th] - [zeros(4,2), rand(4,2)]*[0; 0; W^2; Th^2] - [zeros(2,26); a24; a24];
Error using symengine (line 59)
Array sizes must match.
Error in sym/privBinaryOp (line 903)
Csym = mupadmex(op,args{1}.s, args{2}.s, varargin{:});
Error in - (line 7)
X = privBinaryOp(A, B, 'symobj::zip', '_subtract');
I get stuck trying to subtract a 4 by 1 symbol affiliated matrix columnwise from a double 4 by 26 matrix, so that I can obtain the variables using
FF = solve(F == 0,[U,V,W,Th])
I need help with this problem please. Thanks in anticipation.
  5 件のコメント
Walter Roberson
Walter Roberson 2021 年 7 月 13 日
For this purpose it is marginally important that symbolic expressions are involved.
MATLAB added implicit expansion for numeric values in R2016b.
However, implicit expansion was not added for symbolic expressions until R2017b.
We can deduce that the user is using R2017a or before.
Vincent Ike
Vincent Ike 2021 年 7 月 14 日
Yes @walter Roberson I use R2015a

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2021 年 7 月 13 日
The operation is permitted in current versions:
syms U V W Th
a24 = 0:0.2:5; % which is a step forcing function (in time)
F = rand(4,4)*[U; V; W; Th] - [zeros(4,2), rand(4,2)]*[0; 0; W^2; Th^2] - [zeros(2,26); a24; a24]
F = 
You did not mark your release or mention your release, so the volunteers are entitled to expect that you are using the newest version.
However, I happen to recognize the issue: in sufficiently old versions of MATLAB, implicit expansion did not exist. Furthermore, in old enough versions, bsxfun() could not be used for symbolic expressions.
In versions that old, you have to repmat()
F = repmat(rand(4,4)*[U; V; W; Th] - [zeros(4,2), rand(4,2)]*[0; 0; W^2; Th^2], 1, 26) - [zeros(2,26); a24; a24]
F = 
  7 件のコメント
Walter Roberson
Walter Roberson 2021 年 7 月 15 日
There are four roots per column, not two, if you count the complex solutions. You are working with a quartic.
It would be common to want to filter down to real values.
format long
syms U V W Th
a24 = 0:0.2:5; % which is a step forcing function (in time)
F = repmat(rand(4,4)*[U; V; W; Th] - [zeros(4,2), rand(4,2)]*[0; 0; W^2; Th^2], 1, 26) - [zeros(2,26); a24; a24]
F = 
size(F)
ans = 1×2
4 26
[solTh, solU, solV, solW] = arrayfun(@(COL) solve(F(:,COL), [Th, U, V, W], 'MaxDegree', 4), 1:size(F,2), 'uniform', 0);
Thvals = cell2mat(cellfun(@double, solTh, 'uniform', 0))
Thvals =
-0.094682841308648 - 1.169458034215385i 2.086480594346070 + 0.000000000000000i 2.077784406966989 + 0.000000000000000i 2.066795882117770 + 0.000000000000000i 2.053794533719276 + 0.000000000000000i 2.038985728582344 + 0.000000000000000i 2.022522049377702 + 0.000000000000000i 2.004516987533478 + 0.000000000000000i 1.985053995067856 + 0.000000000000000i 1.964192590106933 + 0.000000000000000i 1.941972506033464 + 0.000000000000000i 1.918416480745901 + 0.000000000000000i 1.893532051138880 + 0.000000000000000i 1.867312574149251 + 0.000000000000000i 1.839737600058620 + 0.000000000000000i 1.810772653755723 + 0.000000000000000i 1.780368421188653 + 0.000000000000000i 1.748459280706609 + 0.000000000000000i 1.714961052314520 + 0.000000000000000i 1.679767749597541 + 0.000000000000000i 1.642746990646218 + 0.000000000000000i 1.603733524609510 + 0.000000000000000i 1.562520003400327 + 0.000000000000000i 1.518843566340973 + 0.000000000000000i 1.472365792402213 + 0.000000000000000i 1.422641643933716 + 0.000000000000000i -0.094682841308648 + 1.169458034215385i -0.191588462920180 + 0.000000000000000i -0.308693627863736 + 0.000000000000000i -0.383827289614846 + 0.000000000000000i -0.434142419854720 + 0.000000000000000i -0.468377862190450 + 0.000000000000000i -0.491368986603327 + 0.000000000000000i -0.506014476764549 + 0.000000000000000i -0.514166684625613 + 0.000000000000000i -0.517068833132778 + 0.000000000000000i -0.515586704069267 + 0.000000000000000i -0.510339554292225 + 0.000000000000000i -0.501778068300653 + 0.000000000000000i -0.490232746397509 + 0.000000000000000i -0.475944888940360 + 0.000000000000000i -0.459086817629438 + 0.000000000000000i -0.439775100856340 + 0.000000000000000i -0.418078966958619 + 0.000000000000000i -0.394025160701052 + 0.000000000000000i -0.367599905080814 + 0.000000000000000i -0.338748196592134 + 0.000000000000000i -0.307370272150378 + 0.000000000000000i -0.273314637267979 + 0.000000000000000i -0.236366403929786 + 0.000000000000000i -0.196228620500677 + 0.000000000000000i -0.152492309223418 + 0.000000000000000i 0.000000000000000 + 0.000000000000000i 0.004119107756266 - 1.296399624887958i 0.067019783917584 - 1.418624948607412i 0.110080877217749 - 1.529559144442854i 0.141739116536933 - 1.630183653277971i 0.166261240273264 - 1.722318188701896i 0.185988642082023 - 1.807515406888357i 0.202313918084746 - 1.886977745764290i 0.216121518248089 - 1.961626965218137i 0.228003294982134 - 2.032177207998635i 0.238372272487112 - 2.099190557970499i 0.247526710242373 - 2.163116664678125i 0.255688182050097 - 2.224320763805330i 0.263025259593340 - 2.283103665714060i 0.269668817910081 - 2.339716222355765i 0.275722255406068 - 2.394369966943788i 0.281268513303054 - 2.447245064241453i 0.286375016595215 - 2.498496341645928i 0.291097227662477 - 2.548257929195656i 0.295481251210847 - 2.596646876044579i 0.299565776442169 - 2.643766003083962i 0.303383547239644 - 2.689706177909450i 0.306962490403037 - 2.734548147533245i 0.310326592263617 - 2.778364028616950i 0.313496587518443 - 2.821218529669286i 0.316490506114062 - 2.863169961402136i 2.092496029555718 + 0.000000000000000i 0.004119107756266 + 1.296399624887958i 0.067019783917584 + 1.418624948607412i 0.110080877217749 + 1.529559144442854i 0.141739116536933 + 1.630183653277971i 0.166261240273264 + 1.722318188701896i 0.185988642082023 + 1.807515406888357i 0.202313918084746 + 1.886977745764290i 0.216121518248089 + 1.961626965218137i 0.228003294982134 + 2.032177207998635i 0.238372272487112 + 2.099190557970499i 0.247526710242373 + 2.163116664678125i 0.255688182050097 + 2.224320763805330i 0.263025259593340 + 2.283103665714060i 0.269668817910081 + 2.339716222355765i 0.275722255406068 + 2.394369966943788i 0.281268513303054 + 2.447245064241453i 0.286375016595215 + 2.498496341645928i 0.291097227662477 + 2.548257929195656i 0.295481251210847 + 2.596646876044579i 0.299565776442169 + 2.643766003083962i 0.303383547239644 + 2.689706177909450i 0.306962490403037 + 2.734548147533245i 0.310326592263617 + 2.778364028616950i 0.313496587518443 + 2.821218529669286i 0.316490506114062 + 2.863169961402136i
Uvals = cell2mat(cellfun(@double, solU, 'uniform', 0))
Uvals =
-1.337768754800854 + 0.370281008481964i 4.147886744121340 + 0.000000000000000i 4.203560186062389 + 0.000000000000000i 4.250258520665525 + 0.000000000000000i 4.289236671744841 + 0.000000000000000i 4.321456315964071 + 0.000000000000000i 4.347670628085559 + 0.000000000000000i 4.368479501435571 + 0.000000000000000i 4.384366836852620 + 0.000000000000000i 4.395726450913830 + 0.000000000000000i 4.402880479358474 + 0.000000000000000i 4.406092656438100 + 0.000000000000000i 4.405577976024064 + 0.000000000000000i 4.401509706214511 + 0.000000000000000i 4.394024388753237 + 0.000000000000000i 4.383225226296037 + 0.000000000000000i 4.369184096585521 + 0.000000000000000i 4.351942302360433 + 0.000000000000000i 4.331510046834908 + 0.000000000000000i 4.307864496160035 + 0.000000000000000i 4.280946127701744 + 0.000000000000000i 4.250652829464192 + 0.000000000000000i 4.216830848578836 + 0.000000000000000i 4.179261067482686 + 0.000000000000000i 4.137637978360862 + 0.000000000000000i 4.091536621178077 + 0.000000000000000i -1.337768754800854 - 0.370281008481964i 0.151621657240662 + 0.000000000000000i 0.315412697274949 + 0.000000000000000i 0.467299478476283 + 0.000000000000000i 0.605192159902538 + 0.000000000000000i 0.730826828987543 + 0.000000000000000i 0.846241109011629 + 0.000000000000000i 0.953172616120265 + 0.000000000000000i 1.053019876536729 + 0.000000000000000i 1.146902914347910 + 0.000000000000000i 1.235728419650252 + 0.000000000000000i 1.320242309412003 + 0.000000000000000i 1.401069436339662 + 0.000000000000000i 1.478743274374451 + 0.000000000000000i 1.553728349607752 + 0.000000000000000i 1.626437574596235 + 0.000000000000000i 1.697246082881442 + 0.000000000000000i 1.766502754777867 + 0.000000000000000i 1.834540366915902 + 0.000000000000000i 1.901685163978232 + 0.000000000000000i 1.968266631030993 + 0.000000000000000i 2.034628350384807 + 0.000000000000000i 2.101141103746500 + 0.000000000000000i 2.168219934876123 + 0.000000000000000i 2.236347949055212 + 0.000000000000000i 2.306111696526823 + 0.000000000000000i 0.000000000000000 + 0.000000000000000i -1.579824069165484 + 0.155947166774068i -1.822634446669780 - 0.006667761087284i -2.055005141088642 - 0.138071360027912i -2.276518693858056 - 0.249708586776252i -2.488523987026801 - 0.347748394596868i -2.692416419616214 - 0.435807057388301i -2.889364746362167 - 0.516180905531849i -3.080310180795550 - 0.590423624507290i -3.266009643248373 - 0.659639629270387i -3.447077546638494 - 0.724645073425437i -3.624018716575809 - 0.786062149931840i -3.797253076349249 - 0.844377379631293i -3.967133996978494 - 0.899979289566606i -4.133962012381135 - 0.953183699362246i -4.297995180163404 - 1.004251238526169i -4.459457005967377 - 1.053399815600127i -4.618542581319673 - 1.100813704462502i -4.775423396142555 - 1.146650302181526i -4.930251155852911 - 1.191045246118383i -5.083160841666774 - 1.234116350680520i -5.234273188741532 - 1.275966679170814i -5.383696711496329 - 1.316686971368663i -5.531529373029692 - 1.356357584047785i -5.677859972074953 - 1.395050058324667i -5.822769303735992 - 1.432828397609563i 4.081554045665995 + 0.000000000000000i -1.579824069165484 - 0.155947166774068i -1.822634446669780 + 0.006667761087284i -2.055005141088642 + 0.138071360027912i -2.276518693858056 + 0.249708586776252i -2.488523987026801 + 0.347748394596868i -2.692416419616214 + 0.435807057388301i -2.889364746362167 + 0.516180905531849i -3.080310180795550 + 0.590423624507290i -3.266009643248373 + 0.659639629270387i -3.447077546638494 + 0.724645073425437i -3.624018716575809 + 0.786062149931840i -3.797253076349249 + 0.844377379631293i -3.967133996978494 + 0.899979289566606i -4.133962012381135 + 0.953183699362246i -4.297995180163404 + 1.004251238526169i -4.459457005967377 + 1.053399815600127i -4.618542581319673 + 1.100813704462502i -4.775423396142555 + 1.146650302181526i -4.930251155852911 + 1.191045246118383i -5.083160841666774 + 1.234116350680520i -5.234273188741532 + 1.275966679170814i -5.383696711496329 + 1.316686971368663i -5.531529373029692 + 1.356357584047785i -5.677859972074953 + 1.395050058324667i -5.822769303735992 + 1.432828397609563i
Vvals = cell2mat(cellfun(@double, solV, 'uniform', 0))
Vvals =
-0.504055209573428 + 0.375368805056658i 1.538127719112909 + 0.000000000000000i 1.890511678779503 + 0.000000000000000i 2.239840799349641 + 0.000000000000000i 2.586550305531252 + 0.000000000000000i 2.930975461892485 + 0.000000000000000i 3.273380473029579 + 0.000000000000000i 3.613977359915537 + 0.000000000000000i 3.952938744999917 + 0.000000000000000i 4.290406771478357 + 0.000000000000000i 4.626499475971578 + 0.000000000000000i 4.961315427222944 + 0.000000000000000i 5.294937147196451 + 0.000000000000000i 5.627433650621144 + 0.000000000000000i 5.958862324873501 + 0.000000000000000i 6.289270296695796 + 0.000000000000000i 6.618695379709691 + 0.000000000000000i 6.947166657143294 + 0.000000000000000i 7.274704720846710 + 0.000000000000000i 7.601321554900924 + 0.000000000000000i 7.927020013930278 + 0.000000000000000i 8.251792794379593 + 0.000000000000000i 8.575620717975008 + 0.000000000000000i 8.898470015403628 + 0.000000000000000i 9.220288065124281 + 0.000000000000000i 9.540996600448889 + 0.000000000000000i -0.504055209573428 - 0.375368805056658i 0.425952114310920 + 0.000000000000000i 0.841967175397670 + 0.000000000000000i 1.245051555178251 + 0.000000000000000i 1.637772165506094 + 0.000000000000000i 2.022531164515393 + 0.000000000000000i 2.401078554174221 + 0.000000000000000i 2.774665087221919 + 0.000000000000000i 3.144202622804048 + 0.000000000000000i 3.510374041664118 + 0.000000000000000i 3.873704412200672 + 0.000000000000000i 4.234607352502596 + 0.000000000000000i 4.593415923112354 + 0.000000000000000i 4.950403771429729 + 0.000000000000000i 5.305800008380226 + 0.000000000000000i 5.659799970539773 + 0.000000000000000i 6.012573234731134 + 0.000000000000000i 6.364269781274358 + 0.000000000000000i 6.715024917878184 + 0.000000000000000i 7.064963406763741 + 0.000000000000000i 7.414203144181120 + 0.000000000000000i 7.762858705799702 + 0.000000000000000i 8.111045091132313 + 0.000000000000000i 8.458882090336328 + 0.000000000000000i 8.806499901058485 + 0.000000000000000i 9.154047044217846 + 0.000000000000000i 0.000000000000000 + 0.000000000000000i -0.289213068042489 + 0.316657961026758i -0.067584248920351 + 0.277225925982538i 0.162037330403100 + 0.247762453617693i 0.398150601647183 + 0.223989032114299i 0.639386853460727 + 0.203854096904311i 0.884738982561576 + 0.186250862023458i 1.133475602093557 + 0.170519225798469i 1.385054471259112 + 0.156233909123522i 1.639063078088668 + 0.143104231345594i 1.895179870072590 + 0.130922155241616i 2.153148753794755 + 0.119533255261260i 2.412761938001932 + 0.108819468524092i 2.673848091629708 + 0.098688314897300i 2.936263965527091 + 0.089065870041373i 3.199888328034980 + 0.079892019272787i 3.464617483931162 + 0.071117153491821i 3.730361901441559 + 0.062699808381617i 3.997043630786747 + 0.054604939049523i 4.264594298815672 + 0.046802633892629i 4.532953530091115 + 0.039267139009943i 4.802067688555977 + 0.031976106629563i 5.071888863590774 + 0.024910008045871i 5.342374044773266 + 0.018051669320386i 5.613484444050670 + 0.011385899926830i 5.885184934307497 + 0.004899192691078i 1.182107457488089 + 0.000000000000000i -0.289213068042489 - 0.316657961026758i -0.067584248920351 - 0.277225925982538i 0.162037330403100 - 0.247762453617693i 0.398150601647183 - 0.223989032114299i 0.639386853460727 - 0.203854096904311i 0.884738982561576 - 0.186250862023458i 1.133475602093557 - 0.170519225798469i 1.385054471259112 - 0.156233909123522i 1.639063078088668 - 0.143104231345594i 1.895179870072590 - 0.130922155241616i 2.153148753794755 - 0.119533255261260i 2.412761938001932 - 0.108819468524092i 2.673848091629708 - 0.098688314897300i 2.936263965527091 - 0.089065870041373i 3.199888328034980 - 0.079892019272787i 3.464617483931162 - 0.071117153491821i 3.730361901441559 - 0.062699808381617i 3.997043630786747 - 0.054604939049523i 4.264594298815672 - 0.046802633892629i 4.532953530091115 - 0.039267139009943i 4.802067688555977 - 0.031976106629563i 5.071888863590774 - 0.024910008045871i 5.342374044773266 - 0.018051669320386i 5.613484444050670 - 0.011385899926830i 5.885184934307497 - 0.004899192691078i
Wvals = cell2mat(cellfun(@double, solW, 'uniform', 0))
Wvals =
0.799679476330780 - 0.841095593907892i -1.592380803469869 + 0.000000000000000i -1.674426897140375 + 0.000000000000000i -1.751966864870528 + 0.000000000000000i -1.825652020612525 + 0.000000000000000i -1.895986058491776 + 0.000000000000000i -1.963367746894912 + 0.000000000000000i -2.028118866002349 + 0.000000000000000i -2.090503174160550 + 0.000000000000000i -2.150739680847249 + 0.000000000000000i -2.209012172212263 + 0.000000000000000i -2.265476190489518 + 0.000000000000000i -2.320264233416095 + 0.000000000000000i -2.373489675456903 + 0.000000000000000i -2.425249746225831 + 0.000000000000000i -2.475627792939262 + 0.000000000000000i -2.524694980011617 + 0.000000000000000i -2.572511526093993 + 0.000000000000000i -2.619127537923073 + 0.000000000000000i -2.664583464619840 + 0.000000000000000i -2.708910159496266 + 0.000000000000000i -2.752128491792144 + 0.000000000000000i -2.794248387207062 + 0.000000000000000i -2.835267074342088 + 0.000000000000000i -2.875166136297033 + 0.000000000000000i -2.913906631752097 + 0.000000000000000i 0.799679476330780 + 0.841095593907892i -0.237720136058116 + 0.000000000000000i -0.444554099309726 + 0.000000000000000i -0.622080124030598 + 0.000000000000000i -0.777863240702378 + 0.000000000000000i -0.917534549677085 + 0.000000000000000i -1.044893165145636 + 0.000000000000000i -1.162544012017425 + 0.000000000000000i -1.272334529393337 + 0.000000000000000i -1.375619727331622 + 0.000000000000000i -1.473423624594866 + 0.000000000000000i -1.566540454409061 + 0.000000000000000i -1.655600263387808 + 0.000000000000000i -1.741112826864168 + 0.000000000000000i -1.823497940488323 + 0.000000000000000i -1.903106899457258 + 0.000000000000000i -1.980238131051339 + 0.000000000000000i -2.055148868114853 + 0.000000000000000i -2.128064105776656 + 0.000000000000000i -2.199183691172421 + 0.000000000000000i -2.268688158280731 + 0.000000000000000i -2.336743784825519 + 0.000000000000000i -2.403507291303494 + 0.000000000000000i -2.469130621645908 + 0.000000000000000i -2.533766365638827 + 0.000000000000000i -2.597574677650533 + 0.000000000000000i 0.000000000000000 + 0.000000000000000i 0.962249250235563 - 0.770907965007232i 1.106689278696621 - 0.731089165352370i 1.234222274922134 - 0.705220050381949i 1.348956411129022 - 0.686548000601008i 1.453959084556002 - 0.672102297646812i 1.551329236491845 - 0.660393363747881i 1.642530219481457 - 0.650587538929500i 1.728617632248514 - 0.642176854853886i 1.810378484561006 - 0.634830771254546i 1.888416678875136 - 0.628322820203841i 1.963207102920860 - 0.622491315078081i 2.035131028873522 - 0.617216892914531i 2.104500031632106 - 0.612408969851718i 2.171572623828648 - 0.607997196681545i 2.236566126669831 - 0.603925859764615i 2.299665336003049 - 0.600150090784758i 2.361028977575994 - 0.596633227988520i 2.420794602321435 - 0.593344933685396i 2.479082358367701 - 0.590259822202744i 2.535997939360069 - 0.587356440792213i 2.591634918780402 - 0.584616499863304i 2.646076619726849 - 0.582024282742178i 2.699397628465569 - 0.579566186932926i 2.751665031439501 - 0.577230363207401i 2.802939435172886 - 0.575006428500804i -1.504961391718419 + 0.000000000000000i 0.962249250235563 + 0.770907965007232i 1.106689278696621 + 0.731089165352370i 1.234222274922134 + 0.705220050381949i 1.348956411129022 + 0.686548000601008i 1.453959084556002 + 0.672102297646812i 1.551329236491845 + 0.660393363747881i 1.642530219481457 + 0.650587538929500i 1.728617632248514 + 0.642176854853886i 1.810378484561006 + 0.634830771254546i 1.888416678875136 + 0.628322820203841i 1.963207102920860 + 0.622491315078081i 2.035131028873522 + 0.617216892914531i 2.104500031632106 + 0.612408969851718i 2.171572623828648 + 0.607997196681545i 2.236566126669831 + 0.603925859764615i 2.299665336003049 + 0.600150090784758i 2.361028977575994 + 0.596633227988520i 2.420794602321435 + 0.593344933685396i 2.479082358367701 + 0.590259822202744i 2.535997939360069 + 0.587356440792213i 2.591634918780402 + 0.584616499863304i 2.646076619726849 + 0.582024282742178i 2.699397628465569 + 0.579566186932926i 2.751665031439501 + 0.577230363207401i 2.802939435172886 + 0.575006428500804i
mask = imag(Thvals) == 0 & imag(Uvals) == 0 & imag(Vvals) == 0 & imag(Wvals) == 0;
[Thvals(mask), Uvals(mask), Vvals(mask), Wvals(mask)]
ans = 52×4
0 0 0 0 2.092496029555718 4.081554045665995 1.182107457488089 -1.504961391718419 2.086480594346070 4.147886744121340 1.538127719112909 -1.592380803469869 -0.191588462920180 0.151621657240662 0.425952114310920 -0.237720136058116 2.077784406966989 4.203560186062389 1.890511678779503 -1.674426897140375 -0.308693627863736 0.315412697274949 0.841967175397670 -0.444554099309726 2.066795882117770 4.250258520665525 2.239840799349641 -1.751966864870528 -0.383827289614846 0.467299478476283 1.245051555178251 -0.622080124030598 2.053794533719276 4.289236671744841 2.586550305531252 -1.825652020612525 -0.434142419854720 0.605192159902538 1.637772165506094 -0.777863240702378
The number of solutions is highly variable. Some of my tests showed as few as two solutions, and some of them showed as high as 84 solutions.
Vincent Ike
Vincent Ike 2021 年 7 月 16 日
Thank you Walter, I have got much insight with your responses. Now, I have a good question here, https://www.mathworks.com/matlabcentral/answers/879973-how-to-solve-four-sets-of-ode-having-four-variables. I hope to learn more from you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

製品


リリース

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by