How do you initialize an N*M matrix?
古いコメントを表示
From the MATLAB help, it says to use:
M = matrix(N, M)
but when I apply this it says that the function 'matrix' is not recognized.
Undefined function 'matrix' for input arguments of type 'double'.
Error in experimental (line 1)
M = matrix(3,3)
3 件のコメント
per isakson
2013 年 6 月 26 日
What does
which matrix
return?
Harry
2013 年 6 月 27 日
Tulike
2017 年 7 月 12 日
M=zeros(N,M)
採用された回答
その他の回答 (5 件)
Lokesh Ravindranathan
2013 年 6 月 26 日
編集済み: Lokesh Ravindranathan
2013 年 6 月 26 日
I am assuming you are trying to create an empty matrix of zeros of dimensions N*M. You can try the following instead
M = zeros(3,3)
This creates a matrix of zeros of size 3*3.
2 件のコメント
per isakson
2013 年 6 月 26 日
編集済み: per isakson
2013 年 6 月 26 日
matrix is a function in the symbolic toolbox.
Lokesh Ravindranathan
2013 年 6 月 26 日
Oh. Thanks Isakson. I will update my answer. My MATLAB did not have symbolic Math toolbox.
Nitin
2013 年 6 月 26 日
0 投票
you could initialize the matrix,
M = zeros(n,m);
Pau
2018 年 10 月 17 日
0 投票
This should make the trick
M = double.empty(N,M,0);
https://uk.mathworks.com/help/matlab/ref/empty.html
Here is the documentation for multi dementional arrays in matlab
Here is an example to create and initialize a 3X3 matric
A = [1 2 3; 4 5 6; 7 8 9]
A = 3×3
1 2 3
4 5 6
7 8 9
HARSHAVARTHINI
2024 年 11 月 26 日
0 投票
% Define the matrix A = [4 1 9; 0 1 3; 0 1 2];
% Initialize parameters n = size(A, 1); % Size of the matrix x = rand(n, 1); % Initial guess for the eigenvector tolerance = 1e-6; % Convergence criteria max_iter = 1000; % Maximum number of iterations lambda_old = 0; % Initial eigenvalue
for k = 1:max_iter % Multiply matrix A with vector x y = A * x;
% Normalize the vector
x = y / norm(y); % Compute the Rayleigh quotient (dominant eigenvalue)
lambda = x' * A * x; % Check for convergence
if abs(lambda - lambda_old) < tolerance
fprintf('Converged in %d iterations.\n', k);
break;
end % Update old eigenvalue
lambda_old = lambda;
end% Display results fprintf('Dominant Eigenvalue: %.6f\n', lambda); disp('Corresponding Eigenvector:'); disp(x);
カテゴリ
ヘルプ センター および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!