noah rivas
noah rivas

Reputation: 1

Matlab error solving symbolic systems of equations as functions of time

I have the following system of differential equations that arose form circuit analysis where the following simplification was made.

Simplification of equations

The systems of equations is as follows:

System of Equations

I created 2 MATLAB files, the first where I define each I_x as a symbolic variable and a second file where I define each I_x as a function of time I_x(t). When I try to find I_4 as a function of time in file 2. I get an error

error: structure has no member 'I4'
error: called from
    Gauging_Circuit at line 12 column 1

Below are the tests I preformed:

% File 1
syms I1 I2 I3 I4 R1 R2 R3 C1 C2 C3 Vi;
eqn1 = Vi == I1*((1/C1) + R1) + I2*(-(1/C1)) +              I3*(0) +            I4*(0);
eqn2 = Vi == I1*(-(1/C1)) +     I2*((1/C1)+(1/C2)+(1/C3)) + I3*(0) +            I4*(0);
eqn3 = Vi == I1*(0) +           I2*(-(1/C3)) +              I3*((1/C3) + R3) +  I4*(0);
eqn4 = Vi == I1*(0) +           I2*(-(1/C2)) +              I3*(0) +            I4*((1/C2)+R2);

% Try lin solve, If it doesnt work, Try solve function below
%[A, B, C, D] = equationsToMatrix([eqn1, eqn2, eqn3, eqn4], [I1, I2, I3, I4]);
%X = linsolve(A,B);

sol = solve([eqn1, eqn2, eqn3, eqn4], [I1, I2, I3, I4]);
disp(sol.I4)

File 1 output: Output From file 1 Screenshot

When I try to make each current a function of time I_x(t) I get an error. Below is the code and output from file 2.

% File 2
syms I1(t) I2(t) I3(t) I4(t) R1 R2 R3 C1 C2 C3 Vi(t);
eqn1 = Vi == I1(t)*((1/C1) + R1) +  I2(t)*(-(1/C1)) +               I3(t)*(0) +           I4(t)*(0);
eqn2 = Vi == I1(t)*(-(1/C1)) +      I2(t)*((1/C1)+(1/C2)+(1/C3)) +  I3(t)*(0) +           I4(t)*(0);
eqn3 = Vi == I1(t)*(0) +            I2(t)*(-(1/C3)) +               I3(t)*((1/C3) + R3) + I4(t)*(0);
eqn4 = Vi == I1(t)*(0) +            I2(t)*(-(1/C2)) +               I3(t)*(0) +           I4(t)*((1/C2)+R2);

% Try lin solve, If it doesnt work, Try solve function below
%[A, B, C, D] = equationsToMatrix([eqn1, eqn2, eqn3, eqn4], [I1, I2, I3, I4]);
%X = linsolve(A,B);

sol = solve([eqn1, eqn2, eqn3, eqn4], [I1(t), I2(t), I3(t), I4(t)]);
disp(sol.I4)

File 2 Output (Actual name is "Gauging_Circuit"):

error: structure has no member 'I4'
error: called from
    Gauging_Circuit at line 12 column 1

Why am I getting this error? When I change both files so that line 12 disp(sol.I4) becomes disp(sol), I get the exact same outputs but addressing I4 gives me an error in the second file.

Upvotes: 0

Views: 46

Answers (0)

Related Questions