# Solving equations involving specific elements of matrices in MATLAB?

• MATLAB
• Urmi Roy
In summary, the conversation is about the use of Matlab to solve equations involving specific elements of two matrices, A and B. The person has attempted to use fsolve and solve, but both have failed. They have also tried using symbolic expressions, but have not been successful. They are seeking help in solving the equations and only require the solution for C1.
Urmi Roy
So let's 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.

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??

syms C1 C2 C3 C4 g L g_0 dL
n=exp(-g*L)
d=exp(-2*g_0*dL)
solve(C1-C2-C3-1, n*C2+C3/n+(d-1)*C4, C1+b*C2-b*C3-1, b*n*C2-b*C3/n-C4(1+d), C1)

## 1. How do I solve equations involving specific elements of matrices in MATLAB?

To solve an equation involving specific elements of matrices in MATLAB, you can use the solve function. This function allows you to specify the variables and equations you want to solve for, and will return the solution in the form of a vector or matrix.

## 2. Can I solve equations involving matrices with complex numbers in MATLAB?

Yes, MATLAB has built-in support for complex numbers, so you can solve equations involving complex matrices using the same methods as for real matrices. Just be sure to use appropriate syntax, such as i for the imaginary unit and conj for complex conjugation.

## 3. How do I input a matrix equation into MATLAB?

You can input a matrix equation into MATLAB using the sym function. This function allows you to create symbolic variables and build equations using them. You can then use the solve function to solve the equation.

## 4. Can I solve equations involving multiple matrices in MATLAB?

Yes, you can solve equations involving multiple matrices in MATLAB. You will need to use the appropriate matrix multiplication and division operators, such as * and /, to perform the necessary calculations.

## 5. Are there any built-in functions in MATLAB for solving matrix equations?

Yes, in addition to the solve function, MATLAB also has built-in functions specifically for solving matrix equations. These include linsolve for solving linear equations, inv for finding the inverse of a matrix, and pinv for calculating the pseudoinverse of a matrix.

• MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
• Engineering and Comp Sci Homework Help
Replies
2
Views
1K
• MATLAB, Maple, Mathematica, LaTeX
Replies
32
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
450
• MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
4K
• MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
9K
• MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
3K