Can you please write the Matlab code for the given problem and its solution, tha
ID: 3143048 • Letter: C
Question
Can you please write the Matlab code for the given problem and its solution, thank you.
Goal: Investigate the charge on a capacitor in an RLC circuit with varying voltage. Tools needed: ode45, plot Description: If Q(t) -charge on a capacitor at time t in an RLC circuit (with R, L and C being the resistance, inductance and capacitance, respectively) and E(t) applied voltage, then Kirchhoff's Laws give the following 2"d order diffcrential cquation for Q(t) LQ'(t) + RQ'(t)-1, Q(t) = E(t) E(t) Questions: Assume L = 1, C= 1/5, R-4 and E(t) 10 cos wt 1. Use ode45 (and plot routines) to plot the solution of (*) with Q(0) = 0 and Q'(0) = 0 over the interval 0Explanation / Answer
MATLAB code
sol = zeros(7,2);
w = [0,0.5,1,2,4,8,16];
for i=1:7
t = 0:80;
q_init = [0;0];
[t,q] = ode45(@ode,t,q_init);
function dqdt = ode(t,q)
q1 = 0;
q2 = 0;
dqdt_1 = 0;
dqdt_2 = 0;
dqdt = [0;0];
dqdt_1 = q2;
dqdt_2 = - 4*q1 - 5*q2 + 10*cos(w(i)*t);
dqdt = [dqdt_1; dqdt_2];
end
sol(i) = [t,y];
end
for i = 1:7
plot(sol(i));
title('w = '%d' ',w(i))
xlable('t')
ylable('q')
end
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.