solving rlc circuit using ode45
23 views (last 30 days)
Show older comments
i have homework to solve rlc circuit using ode45 i tried this code and the question is how to plot Vl1 anyone can help me please and if there is any mistake in this code
function RLC=homework(t,x)
R1=20;R2=30;L1=4*10^-3;L2=2*10^-3;C=0.004;u=100;
RLC(1)=(R1/L1)*(x(1))+(1/L1)*(x(2))-(1/L1)*u;
RLC(2)=-(R2/L2)*(x(2))+(1/L2)*(x(3));
RLC(3)=(-1/C)*(x(1))-(1/C)*(x(2));
RLC=RLC';
[t,x]=ode45('homework',[0 10],[2;2;2]);
2 Comments
James Tursa
on 8 Aug 2018
You are missing a minus sign on the first rhs term on the x1dot line:
RLC(1) = -(R1/L1)*(x(1)) + (1/L1)*(x(2)) - (1/L1)*u;
Accepted Answer
Aquatris
on 9 Aug 2018
If you were to use the code;
[t,y] = ode45(@homework,t,[0 0 0]');
the y here is your i1, i2, and vc.
From here you should know how to get desired Voltages (Kirschof law etc.).
The subplot command will be used as;
subplot(4,1,1),plot(t,Vl1) % "subplot(4,1,2)" means there will be
subplot(4,1,2),plot(t,Vr2) % 4 rows and 1 column in total for
subplot(4,1,3),plot(t,Vr1) % the plots and this one is the 2nd
subplot(4,1,4),plot(t,Vc) % plot
Similar thing for the currents.
In part 4, you just need to replace u in the function with the sine wave.
Is there any particular question you have other than these?
0 Comments
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!