Solving equations involving specific elements of matrices in MATLAB?

Click For Summary
SUMMARY

This discussion focuses on solving equations involving specific elements of matrices in MATLAB using the functions fsolve and solve. The user attempted to solve two equations with matrices A and B but encountered issues with both methods. The equations presented include A(1)+B(2)=4 and A(1)-B(2)=2, and later, a set of equations involving symbolic variables C1, C2, C3, and C4. The user faced difficulties due to symbolic expressions in MATLAB, which led to the need for clarification on the use of fsolve.

PREREQUISITES
  • Understanding of MATLAB syntax and functions
  • Familiarity with numerical solving techniques in MATLAB, specifically fsolve
  • Knowledge of symbolic mathematics in MATLAB, particularly the solve function
  • Basic understanding of matrix operations and element indexing in MATLAB
NEXT STEPS
  • Explore the use of fsolve for solving nonlinear equations in MATLAB
  • Learn about symbolic computation in MATLAB, focusing on the syms and solve functions
  • Investigate matrix indexing and manipulation techniques in MATLAB
  • Review MATLAB documentation on troubleshooting common issues with fsolve and solve
USEFUL FOR

Mathematics students, engineers, and researchers who need to solve complex equations using MATLAB, particularly those working with matrices and symbolic expressions.

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 12 ·
Replies
12
Views
2K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
10K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 32 ·
2
Replies
32
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 2 ·
Replies
2
Views
4K
Replies
1
Views
3K