Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations SSS148 on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple problem for experienced user 1

Status
Not open for further replies.

MachinaMan

Mechanical
Aug 30, 2003
70
Hi all,

For some reason I can't seem to be able to use this function:
Code:
>> 0.206*exp((-3.747*t))*sin(15.36*t)
??? Error using ==> *
Inner matrix dimensions must agree.
You can see the associated error message, can someone help me please ?

By the way,
Code:
t=0:0.01:10;
Thanks,
-R
 
Replies continue below

Recommended for you

You forgot a ".":

Code:
0.206*exp((-3.747*t)).*sin(15.36*t)
 
Thanks jisb !

I knew it was simple ... I never was familiar with the ".*" operator.

Thanks for the quick reply

-R
 
Frenchcanuck,

what your first line does is multiply 2 line vectors using the matrix multiplication.

As what you want is to do element-by-element multiplication, you have to use the ".*" operator where necessary:

Code:
0.206*exp((-3.747*t)).*sin(15.36*t)

quicker than me, jisb ;-)
 
Hi Tompouce,

So if I am getting this correctly, since I want to plot this function, I need several values therefor I need to multiply them on an element by element basis ? Is this correct ?
 
The exponential and sinusoid terms you are multiplying are both vectors of dimension 1 x length(t). Your original code tried to multiply them, but to multiply two matrices, their inner dimension must agree. For example, if A is (mxn) and B is (nxp), A*B is of dimension (mxn)*(nxp), or (mxp). B*A is not defined, as that would result in (nxp)*(mxn), and the inner dimensions don't "cancel" each other.

In this case, length(t) is 1001. You originally tried to multiply (examining the dimension only) (1x1001)*(1x1001). If you look at the inner two dimensions, i.e., 1001)*(1, they are of different sizes. What you were really tring to do is to multiply the magnitudes of the two terms evaluated at each individual point in vector t (i.e., perform element by element multiplication, as tompouce indicated), not multiply the two vectors. This will result in an answer that is 1x1001 in dimension, which can then be plotted against t, since to plot, the lengths of the two vectors must also be equal.

xnuke

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
you're right frenchcanuck

as you're only working on the same function calculated at different times, you need to do an element by element multiplication (in opposition to on a single calculation using matrix arguments)

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor