Solve an algebraic matrix equation
2 ビュー (過去 30 日間)
古いコメントを表示
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
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.
採用された回答
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]
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]
7 件のコメント
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]
size(F)
[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))
Uvals = cell2mat(cellfun(@double, solU, 'uniform', 0))
Vvals = cell2mat(cellfun(@double, solV, 'uniform', 0))
Wvals = cell2mat(cellfun(@double, solW, 'uniform', 0))
mask = imag(Thvals) == 0 & imag(Uvals) == 0 & imag(Vvals) == 0 & imag(Wvals) == 0;
[Thvals(mask), Uvals(mask), Vvals(mask), Wvals(mask)]
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.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!