0

I have to represent this function: c = y * sin(x) using mesh. Where:

x = -10:10
y = 0:3:30

My code looks like this:

[X,Y] = meshgrid(x,y);
C = Y*sin(X)';
mesh(X,Y,C);

But when I run it I get the following error:

"Error using mesh (line 71) Data dimensions must agree.".

How do I fix this? I'm not sure how to plot a function where the variables are multiplied.

1 Answer 1

1

I don't have a MATLAB licence to test it. But I guess the problem is that you are using the * operator, which does a matrix matrix multiplication. You need to do an element-wise multiplication using .*, and remove the transpose.

C = Y.*sin(X);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.