Solving equations involving specific elements of matrices in MATLAB?

  • #1
753
1

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.
 

Answers and Replies

  • #2
kreil
Insights Author
Gold Member
668
67
Why do you need to use fsolve?

Code:
myfun(A,B)

ans =

    -2
    -2
 
  • #3
9
0
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??

Any help please?

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)
 

Related Threads on Solving equations involving specific elements of matrices in MATLAB?

  • Last Post
Replies
2
Views
3K
Replies
1
Views
4K
  • Last Post
Replies
5
Views
4K
  • Last Post
Replies
2
Views
2K
Replies
28
Views
54K
Replies
3
Views
1K
  • Last Post
Replies
3
Views
3K
Replies
1
Views
3K
  • Last Post
Replies
2
Views
2K
Replies
1
Views
2K
Top