Multiplying two matrices with completely different dimensions

Hi everybody. I've programmed the following code:
[X,Y,Z]=meshgrid(0:.1:10);
B=[0.0184 0 0; 0 00.0546 0; 0 0 0.0248];
p = densitet(X,B);
function p = densitet(U, B)
p =((det(inv(B))/(8.*pi.^3)).^(0.5))*exp(-0.5*transpose(U).*inv(B).*U) ;
end
Now it gives the following errors:
Error using .' Transpose on ND array is not defined. Use PERMUTE instead.
Error in Try>densitet (line 17) p =((det(inv(B))/(8.*pi.^3)).^(0.5))*exp(-0.5*transpose(U).*inv(B).*U) ;
Error in Try (line 13) p = densitet(X,B);
Can anybody help my fix the code, so that it works?
Edit: I may need to clarify that I want my function p to work on the whole meshgrid - if that makes sense.
Thanks in advance!

4 件のコメント

Stephen23
Stephen23 2018 年 2 月 8 日
編集済み: Stephen23 2018 年 2 月 8 日
"Can anybody help my fix the code, so that it works?"
Did you read the error message? It tells you how to solve that error:
"Transpose on ND array is not defined. Use PERMUTE instead."
Did you read the permute help and give it a try?
Maja Bernstorff
Maja Bernstorff 2018 年 2 月 8 日
But then I get the following error message
Array dimensions must match for binary array op.
I think the problem is that I'm trying to multiply a 101x101x101 matrix with a 3x3 matrix, which obviously gives some complications. I just don't know how to solve it no matter how much I google
Birdman
Birdman 2018 年 2 月 8 日
The solution is obvious. You can change your B matrix :)
Adam
Adam 2018 年 2 月 8 日
Before thinking how to do it in Matlab you should ask yourself what you expect the answer to be and whether it even makes sense in theory. what do you expect the result to be of multiplying a 101x101x101 array by a 3x3 array?

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

タグ

質問済み:

2018 年 2 月 8 日

コメント済み:

2018 年 2 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by