MATLAB Solving equations involving specific elements of matrices in MATLAB?

Click For Summary
The discussion focuses on solving equations involving specific elements of matrices A and B in MATLAB. The user attempts to use the fsolve function to solve two equations but encounters issues with their implementation. Additionally, another user seeks help with solving four equations for variables C1, C2, C3, and C4, expressing concerns about MATLAB getting stuck due to symbolic expressions. Both users are looking for effective solutions to their respective problems using MATLAB's capabilities. The thread highlights challenges faced when using fsolve and symbolic solving in MATLAB.
Urmi Roy
Messages
743
Reaction score
1
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.
 
Physics news on Phys.org
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??

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)
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 4 ·
Replies
4
Views
10K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 32 ·
2
Replies
32
Views
4K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 2 ·
Replies
2
Views
4K
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K