'Matrix dimensions must agree error'

3 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Ameer Hamza
Ameer Hamza il 7 Mag 2020
Modificato: Ameer Hamza il 7 Mag 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)

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by