Tips for solving Matrix/Linear Algebra Problems with matlab

2 次查看(过去 30 天)
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