
'Matrix dimensions must agree error'
3 views (last 30 days)
Show older comments
Aditya Jadhav
on 7 May 2020
Commented: Aditya Jadhav
on 7 May 2020
bbfun = @(x1,x2) (4-2.1.*x1.^2+x1.^4/3).*x1.^2 + x1.*x2 + (-4+4*x2.^2) .*x2.^2;
x1 = -2:1/100:2;
x2 = -1.5:1/100:1.5;
pltvar = bbfun(x1,x2);
contour(x1,x2,pltvar,20)
Error:
Matrix dimensions must agree.
Error in q2_a>@(x1,x2)(4-2.1*x1.^2+x1.^4/3).*x1.^2+x1.*x2+(-4+4*x2.^2).*x2.^2
Error in q2_a (line 5)
pltvar = bbfun(x1,x2);
Why am I getting this error? What am I doing wrong?
0 Comments
Accepted Answer
Ameer Hamza
on 7 May 2020
Edited: Ameer Hamza
on 7 May 2020
You need a mesh to create contour plot
bbfun = @(x1,x2) (4-2.1.*x1.^2+x1.^4/3).*x1.^2 + x1.*x2 + (-4+4*x2.^2) .*x2.^2;
x1 = -2:1/100:2;
x2 = -1.5:1/100:1.5;
[X1, X2] = meshgrid(x1, x2);
pltvar = bbfun(X1, X2);
contour(X1, X2, pltvar,20)

More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!