Raising a scalar to each element in a matrix

2 ビュー (過去 30 日間)
J
J 2022 年 5 月 17 日
編集済み: Torsten 2022 年 5 月 17 日
I have tried to raise e to the power of each element of a matrix for a contour plot of e^(1/X)/Y and got the error message for non-finite ZData. I was wondering whether the operation has done a form of matrix multiplication and added multiple elements results instead of outputting e^(ij) for element ij.
Thanks
x = linspace(0,50);
y = linspace(0,50);
[X,Y] = meshgrid(x,y);
Z = expm(X.^(-1))*(Y.^(-1));
contour(X,Y,Z);
Warning: Contour not rendered for non-finite ZData

回答 (1 件)

Torsten
Torsten 2022 年 5 月 17 日
編集済み: Torsten 2022 年 5 月 17 日
expm is incorrect, use exp.
And you shouldn't divide by 0 - not for X and not for Y.
x = linspace(1,50);
y = linspace(1,50);
[X,Y] = meshgrid(x,y);
Z = exp(1./(X.*Y));
contour(X,Y,Z)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by