how to properly write this equation exp(x)cos(y)

I wrote it like exp(x).*cos(y) but I kept getting "Matrix dimensions must agree" as output

3 Comments

What are size(x) and size(y) and what size of output are you expecting?
[y]=meshgrid(-1:0.5:1); [x]=meshgrid(-2*pi:0.5:2*pi);
Your y is 5 x 5. Your x is 26 x 26. What size of output are you looking for?

Sign in to comment.

 Accepted Answer

Matt J
Matt J on 28 Nov 2017
Edited: Matt J on 28 Nov 2017
This might be what you want,
[y,x]=meshgrid(-1:0.5:1,-2*pi:0.5:2*pi);
exp(x).*cos(y)

More Answers (1)

An interesting, creative, yet terrible use of meshgrid. Instead, do this:
[x,y] = meshgrid(-2*pi:0.5:2*pi,-1:0.5:1);
Read the help when you will use a function you don't understand. Try some simple examples. Think about what you see in those examples.
By the way, This is usually a bad idea:
-2*pi:0.5:2*pi
ans =
Columns 1 through 13
-6.2832 -5.7832 -5.2832 -4.7832 -4.2832 -3.7832 -3.2832 -2.7832 -2.2832 -1.7832 -1.2832 -0.78319 -0.28319
Columns 14 through 26
0.21681 0.71681 1.2168 1.7168 2.2168 2.7168 3.2168 3.7168 4.2168 4.7168 5.2168 5.7168 6.2168
Because the final point will not be 2*pi. So expect to see some artifacts of that at some point in time if you do this sort of thing often. Instead, learn to use linspace.

Community Treasure Hunt

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

Start Hunting!