Tips for solving Matrix/Linear Algebra Problems with matlab

2 Ansichten (letzte 30 Tage)
Annie
Annie am 2 Mai 2025
Kommentiert: Torsten am 2 Mai 2025
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?

Akzeptierte Antwort

Sam Chak
Sam Chak am 2 Mai 2025
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 Kommentare
Annie
Annie am 2 Mai 2025
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?
Torsten
Torsten am 2 Mai 2025
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 = 

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by