How multiply cos and sin (eg. cos(pi*x).*sin(pi*y))

7 views (last 30 days)
Hi All,
I have a value for out1 using the below code
out1=double(int(int((exp(x+y)*cos(pi*x)*cos(pi*y)),x,-1,1),y,-1,1))
I would like to multiply cos(pi*x).*sin(pi*y)) by out1 by passing the same range for x and y.
My code is like below
out1=double(int(int((exp(x+y)*cos(pi*x)*cos(pi*y)),x,-1,1),y,-1,1))
answer1=cos(pi*x).*sin(pi*y)
answer2 = out1.*answer1
I am getting the below error,
Error using *
Inner matrix dimensions must agree.
Thanks,
With regards,
GK.Jagatheswari

Answers (1)

Image Analyst
Image Analyst on 1 Apr 2014
Are x and y arrays? Or scalars in a loop?
whos x
whos y
What does it report in the command window? It seems like they're arrays, and it so you must use .* instead of * before the cos()
out1=double(int(int((exp(x+y) .* cos(pi*x) .* cos(pi*y)),x,-1,1),y,-1,1))
because you're multiplying an array by an array element-by-element. Otherwise it will do a matrix multiplication and you'll get an error message like that.
  2 Comments
jagatheswari kathirvel
jagatheswari kathirvel on 1 Apr 2014
Hi, There is no problem in evaluating out1. I got the answer. Again with out1, I want to multiply cos(pi*x) and cos(pi*y), because that is the definition of fourier sereis in two dimension.Iam getting an error message saying that Error using * Inner matrix dimensions must agree..Please help. Otherwise is there any direct way to multiply cos(pi*x) and cos(pi*y) with b1.
Image Analyst
Image Analyst on 1 Apr 2014
Give the exact error message. Quit snipping out just a part of it. Post ALL the red text, line number, everything .

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!