Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



Re: Assigning different values for variable issue
Posted:
Feb 1, 2013 9:43 AM


"Matthew " <mdforman91@hotmail.com> wrote in message news:kefj4h$6r$1@newscl01ah.mathworks.com... > So what I'm trying to do is simulate different damping ratios (labeled > "C") and simply use those in a bunch of equations for outputting a plot of > the displacement. However I'm having matrix agreement issues and I can't > figure out why. My code is: > > t=0:0.1:5; > C=[.01 .2 .6 .1 .4 .8]; > Wn=2; > Wd=Wn*sqrt(1C.^2); > A=sqrt(((C.*Wn*1).^2 + Wd.^2)./(Wd.^2)); > phi=atan(Wd./(C.*Wn*1)); > x=A.*exp(C.*Wn*t).*sin(Wd.*t + phi); > plot(x,t) > > I've found that the issue takes place in my "x" equation between Wn*t and > I can't figure out what is wrong. Excuse all the dot assignments, as I'm > not sure if all them were needed or not.
.* is elementwise multiplication. The two quantities being multiplied must be EXACTLY the same size (in which case the result is that same size) or one must be scalar (in which case the result is the size of the other.)
* is matrix multiplication. The number of columns in the first quantity being multiplied must be equal to the number of rows in the second (in which case the result has the same number of rows as the first and the same number of columns as the second), or one must be scalar (in which case the result is the size of the other.)
Since Wn is scalar the multiplication C.*Wn is valid and results in a vector the same size as C. Then (C.*Wn)*t is attempting to perform matrix multiplication on two vectors that do NOT satisfy the requirements, and that's the cause of the problem. I'm guessing you want to perform elementwise multiplication there, but C and t are not the same size so that won't work. You may want to change your t to something like:
t = 0:1:5;
and use elementwise multiplication.
 Steve Lord slord@mathworks.com To contact Technical Support use the Contact Us link on http://www.mathworks.com



