Tips for solving Matrix/Linear Algebra Problems with matlab

조회 수: 4 (최근 30일)
Annie
Annie 2025년 5월 2일
댓글: Torsten 2025년 5월 2일
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?

채택된 답변

Sam Chak
Sam Chak 2025년 5월 2일
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
Annie
Annie 2025년 5월 2일
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 2025년 5월 2일
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개)

카테고리

Help CenterFile Exchange에서 Applications에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by