MATLAB: RLC circuit equation problem

circuit

Can some one tell me where I'm going wrong with this code?
I need to write a program that plots 2d graphics of the current (i) against time (t) with time changing from 0:0.001:0.4 seconds.
This is what I have so far:

Best Answer

If you haven’t already solved it by now, you need to incorporate ‘t’ into your equation. Note that including it in ‘omega’ will make your code work:
Vm=240; f=50; R=5; L=0.004; C=0.0015; t=0:0.001:0.04;
for k1=1:length(t)
omega=2*pi*f*t(k1);
z(k1)=sqrt(R^2)+(omega*L-(1./(omega*C)).^2);
i(k1)=Vm/z(k1);
end;
plot(t, i)