Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


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

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: 17,944
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 " <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(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
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com





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

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.