0

I just want to plot the function h(x,y)=(xsin(20y)+ysin(20x))^2cosh(sin(10x)x)+(xcos(10y)−ysin(10x))^2cosh(cos(20y)y) and I have the code

clear;
close all;
h=inline('(x*sin(20*y)+y*sin(20*x)).^2*cosh(sin(10*x)*x)+(x*cos(10*y)-y*sin(10*x)).^2*cosh(cos(20*y)*y)','x','y');

x=-3:0.01:3;
y=-3:0.01:3;
for i=1:length(x)
    z(:,i)=h(x(i),y);
end
figure(1);
mesh(x,y,z);
xlabel('x','fontsize',14);
ylabel('y','fontsize',14);
zlabel('h(x,y)','fontsize',14);

Why it always gives the response:

Error using inlineeval (line 14) Error in inline expression ==> (x*sin(20*y)+y*sin(20*x)).^2*cosh(sin(10*x)x)+(xcos(10*y)-y*sin(10*x)).^2*cosh(cos(20*y)*y) Inner matrix dimensions must agree.

Error in inline/subsref (line 23) INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr, INLINE_OBJ_.expr);

Error in hw7_2 (line 8) z(:,i)=h(x(i),y);

This is why? Any help will be appreciated! Thanks in advance!

1
  • The error message says it all really, Inner matrix dimensions must agree.. Matlab error messages are very useful, always read them! Commented Mar 23, 2015 at 23:57

1 Answer 1

2

You probably meant to use pointwise multiplication (.*) instead of matrix multiplication (*). I.e. instead of x*sin(20*y) you should use x.*sin(20*y), etc. This will mutliply each element of the array x by each element of the array sin(20*y), which is likely the desired behavior.

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.