The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Assigning different values for variable issue
Replies: 1   Last Post: Feb 1, 2013 9:43 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Steven Lord

Posts: 18,038
Registered: 12/7/04
Re: Assigning different values for variable issue
Posted: Feb 1, 2013 9:43 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Matthew " <> wrote in message
> 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(1-C.^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
To contact Technical Support use the Contact Us link on

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.