# Solving equations involving specific elements of matrices in MATLAB?

• MATLAB

## Main Question or Discussion Point

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.

Related MATLAB, Maple, Mathematica, LaTeX News on Phys.org
kreil
Gold Member
Why do you need to use fsolve?

Code:
myfun(A,B)

ans =

-2
-2

Solving 4 equations for 4 unknowns

Hi I am trying to solve the following equations using Matlab for C1, C2, C3 and C4. In real fact I only require C1.

C1-C2-C3-1=0
n*C2+C3/n+(d-1)*C4=0
C1+b*C2-b*C3-1=0
b*n*C2-b*C3/n-C4(1+d)=0

This is what I have input in Matlab but it seems its getting stuck because of the symbolic expresssion??