How can I fix error "matrix dimensions must agree" in this code?

pd=makedist('normal', 'mu', 4.5, 'sigma', 1.25);
rang(1)
h=random(pd, 601,1);
b=5;
c:0.05;
S=1000;
betas=0.5;
betao=0.7;
y=linspace(0, 60, 100);
x=linspace(0, 60, 102);
[X,Y]=meshgrid(x,y);
Z=(sum((S-X+min(b*(max(0,h-6)),Y)-b*(max(0,h-6))).^(1-betao))/(1-betao))/lenght(h)...
+(0.7*sum(((X-(c\2)*6^2-min(b*(max(0,h-6)),Y)).^(1-betas))/(1-betas))/lenght(h)));
[X,Y,Z]=peaks;
contour(X,Y,Z,20)

7 commentaires

because S is a scalar and X is a matrix how can you subtract them???
Thank you very much! My goal is to create a 3D plot with X and Y as my independent variables but I can not convert these vectors to matrices to create a surface or contour of my function because I will have an issue with matrices dimensions. How can I best approach this? Much appreciated.
@madhan, "S is a scalar and X is a matrix how can you subtract them", see Compatible Array Sizes for Basic Operations
h is 601 x 1 . h-6 is the same size. max of 0 and that is the same size .
x is 100 long and y is 102 long so ndgrid of the two will make X and Y into 100 x 102.
You then try to min() between X of 100 x 102 and the result of the max at 601 x 1. Those sizes are incompatible .
What size were you expecting from the results of the min()?
@Per Isakson thank you
@Walter Roberson, thank you very much for taking time to comment on this. As you mention in your post, by sizing the min at 100 x 100 and the max at 100 x 1 would solve the error "Matrix dimensions agree". Then a second error appears in relation to the size of Z "Z must be a matrix, not a scalar or vector". That can be solved by taking the non-random parameters outside the integral. This allows me to create a 3D plot with surf.
min(b*(max(0,h-6)),Y)
The above line shows error. The dimensions of input to min re different.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Contour Plots dans Centre d'aide et File Exchange

Produits

Version

R2017b

Tags

Commenté :

le 19 Nov 2018

Community Treasure Hunt

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

Start Hunting!

Translated by