Why do i keep getting that the inner matrix dimensions must agree? i trying to plot this equation vs time but it keeps giving me this error, even if i use the '.*t' format

q0 = 10;
R = 60;
L = 9;
C = 0.00005;
t = linspace(0.1,0.8,8);
q(t) = (q0)*exp((-R.*t)/(2*L))*cos(sqrt((1/(L*C))-((R/(2*L))^2)).*t);
plot(q(t),t,'-r')

Answers (1)

Converting the mtimes to a times removes the error:
q = (q0)*exp((-R.*t)/(2*L)).*cos(sqrt((1/(L*C))-((R/(2*L))^2)).*t);
^
But you are the only one who knows if it is correct or not.
I also removed the indexing using t, which makes no sense.

5 Comments

I'm still getting the same error, I'm pretty sure the equation is written correctly, so I can't find the problem
Here is the complete code, with the two changes that I mentioned in my Answer:
q0 = 10;
R = 60;
L = 9;
C = 0.00005;
t = linspace(0.1,0.8,8);
q = (q0)*exp((-R.*t)/(2*L)).*cos(sqrt((1/(L*C))-((R/(2*L))^2)).*t);
plot(q,t,'-r')
it works without error. Whether it is correct is a different matter entirely.
I copied and pasted your initial assignments and Stephen's version of your q, and that does not give me any error. The end result is a 1 x 8 vector.
My pleasure. You can also Accept the answer answer that best resolves your question.

Sign in to comment.

Categories

Tags

Asked:

on 8 Feb 2016

Commented:

on 9 Feb 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!