Solving equations involving specific elements of matrices. Is this possible on MATLAB?

1 回表示 (過去 30 日間)
Yagnaseni Roy
Yagnaseni Roy 2014 年 3 月 24 日
編集済み: Matt J 2014 年 3 月 24 日
So lets say I have 2 matrices A and B. I need to solve 2 eqns involving specific elements of each matrix. e.g. A(1)+B(2)=4; A(1)-B(2)=2.
Is there any way to do this? My efforts with Fsolve and solve have failed. Here's what I've done so far:
function F=myfun(A,B)
F=[A(1)-B(2)-2;
A(1)+B(2)-4];
end
In the command window I typed:
>>A=ones(2,2);
>> B=ones(2,2);
>> [A,B]=fsolve(@myfun,A,B)
I even tried
[A(1),B(1)]=fsolve(@myfun,A(1),B(1))
Neither attempt worked.

回答 (1 件)

Matt J
Matt J 2014 年 3 月 24 日
編集済み: Matt J 2014 年 3 月 24 日
Since the equations are linear, you should just use MLDIVIDE
x = [1 -1; 1 +1]\[2;4]
A(1)=x(1);
B(2)=x(2);
  2 件のコメント
Yagnaseni Roy
Yagnaseni Roy 2014 年 3 月 24 日
This is just a simplified version (kind of a schematic representation) of the set of equations I'm trying to solve which are actually extremely complicated and non-linear!
Matt J
Matt J 2014 年 3 月 24 日
編集済み: Matt J 2014 年 3 月 24 日
If you were to solve the linear equations in your example with FSOLVE, it would look like this
function F=myfun(z)
F = [1 -1; 1 +1]*z(:) - [2;4]
end
and then something like,
z=fsolve(@myfun,[1,1]);
If you then want the solution variables, z(i), placed inside specific matrix entries, you are free to do so by direct assignment, e.g.,
A(1,1)=z(1);
B(2,1)=z(2);

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

カテゴリ

Help Center および File ExchangeSystems of Nonlinear Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by