Tips for solving Matrix/Linear Algebra Problems with matlab

So, take for example some system of equations. If I have 3 equations assosciated with each loop, but different coeffcients, how would I go about writing a script to solve for such problems? Like for example, circuit analysis or something of that nature. The coeffcients change for every loop, and the amount of coeffcients varies for every problem. I would like to create a real solver.
  • How would I organize the matrices if every situation is unique
  • How could I write it in a loop?

 채택된 답변

RLC Circuit analysis typically involves a dynamic system. Thus, you will need to model it in the form of a differential equation and then solve it either using ode45 or dsolve (if your professor insists on seeing the analytical solution).
If the circuit consists solely of resistors, you can apply Kirchhoff's circuit laws and then use the equationsToMatrix() function to convert the linear equations to matrix form. After that, you can easily solve the matrix form of the equations using the linsolve() function.
Here's a simple demo:
syms x y z
eqns = [x + y - 2*z == 0, % Mesh #1
x + y + z == 1, % Mesh #2
2*y - z == -5]; % Mesh #3
[A, b] = equationsToMatrix(eqns)
A = 
b = 
X = linsolve(A, b)
X = 

댓글 수: 4

This is pretty neat! Is there a way to change the symbol you are using based on a vector of numbers? Or change what symbol is being multiplied to a coefficent based on a condition?
You can declare a vector of symbolic scalar variables using the followng syntax:
syms v [1, 6]
v
v = 
You can also find various examples here:
Take a look as this example:
syms i [1 3]
R1 = 100;
R2 = 200;
R3 = 300;
E1 = 3;
E2 = 4;
eqns = [ i1 - i2 - i3 == 0,
-R2*i2 + E1 - R1*i1 == 0,
-R3*i3 - E2 - E1 + R2*i2 == 0]
eqns = 
[A, b] = equationsToMatrix(eqns)
A = 
b = 
I = linsolve(A, b)
I = 
so I'm doing that
eqns(1:3) = [p1*Piny+h1*vy+r*ry+fy*f1 == F,
Pinx*p2+vx*h2+fx*f2 == 0,
f3*M+vy*dm4*h3+Piny*p3*dm2+ry*r3*dm3 == m1];
I want to store it in this vector, but the sizes don't match?
It says the length of it is 2, but it's 3?
Maybe some variable or parameter is empty - we cannot say without your complete code.
Usually, it should work:
syms x y z
eqns(1:3) = [x == 5,
y == 0,
z == -7]
eqns = 

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Applications에 대해 자세히 알아보기

질문:

2025년 5월 2일

댓글:

2025년 5월 2일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by