如何在 Matlab 中对具有两个矩阵的系统进行数值求解?

How to numerically solve a system with two matrices in Matlab?

我正在尝试从数值上找到 A*cos x +B*sin x = C 的解,其中 A 和 B 是两个已知的相同大小的方阵(例如 100x100),C 是一个已知向量 (100x1)。 如果没有第二项(即使用单个矩阵),我将使用 Jacobi 或 Gauss-Seidel 来解决这个问题并得到 x 但在这里,我看不到如何在 Matlab 中继续解决这个问题。 可能是,将问题解决为:A*X + B*sqrt(1-X^2) = C.

会很有用

如果有任何帮助、想法或建议,我将不胜感激 提前致谢

如果我没理解错的话,你可以像这样使用 fsolvecX 是向量):

A = ones(2,2);
B = ones(2,2);
c = ones(2,1);

% initial point
x0 = ones(length(A), 1);
% call to fsolve
sol = fsolve(@(x) A * cos(x) + B*sin(x) - c, x0);

在这里,我们用F: R^N -> R^NF(x) = A * cos(x) + B*sin(x) - c求解非线性方程组F(x) = 0

只是为了完整起见,这是我之前的回答,即如果 CX 是矩阵而不是向量,该怎么办:

A = ones(2,2);
B = ones(2,2);
C = ones(2,2);

% initial point
x0 = ones(numel(A), 1);

% call to fsolve
fsolve(@(x) fun(x, A, B, C), x0)


function [y] = fun(x, A, B, C)
    % Transform the input vector x into a matrix
    X = reshape(x, size(A));
    % Evaluate the matrix equation
    Y = A * cos(X) + B*sin(X) - C;
    % flatten the matrix Y to a row vector y
    y = reshape(Y, [], 1);
end

这里的思路是将矩阵方程组F: R^(N x N) -> R^(N x N)转化为等效的非线性系统F: R^(N*N) -> R^(N*N).