Filter löschen
Filter löschen

How can I create a function which outputs two variables for calculating the eigenvalue * eigenvector

2 Ansichten (letzte 30 Tage)
m1 = [7 3; 3 -1] % Matrix
[Vectors, DiagonalWithValues] = eig(m1)
ListEvalues = diag(DiagonalWithValues)
How can I implement a function which takes these 3 inputs (1. initial matrix, 2. eigenvectors, 3.eigenvalues) and returns two variables
1. a boolean variable, which indicates if both are equal
2. result of the operation for example if they are not equal it should return -1

Antworten (1)

Nithin
Nithin am 10 Okt. 2023
Bearbeitet: Nithin am 10 Okt. 2023
Hi Jonas,
I understand that you want to create a function which outputs two variables on calculating the product of eigen value and eigen vector and then write a condition to generate the function output based on the match or mismatch of the variables.
To implement this function, kindly refer to the following code snippet -
M1 = [7 3; 3 -1] %given matrix
[eigenvectors, eigenvalues] = eig(M1);
function [isEqual, result] = checkEigenMatch(M1, eigenvalues, eigenvectors)
% Calculate the product of M1 * eigenvectors
product = M1 * eigenvectors;
% Calculate the product of eigenvalues * eigenvectors
productEigen = eigenvalues * eigenvectors;
% Check if the two products are equal within a small tolerance
tolerance = 1e-6;
isEqual = isequal(product, productEigen, tolerance);
% Set result based on the comparison
if isEqual
result = true;
else
result = -1;
end
end
To know more information regarding the calculation of eigen vectors and eigen values, kindly refer to the following documentation:
I hope this answer resolves your query.
Regards,
Nithin Kumar.
  1 Kommentar
Dyuman Joshi
Dyuman Joshi am 10 Okt. 2023
@Nithin, Please don't do obvious homework questions on MATLAB Answers, when no effort has been shown. This does not help the student, who learns nothing more than to post all of their homwork problems on the site, hoping they will find someone willing to do their thinking and work for them. Worse that that, it convinces the next student who comes along to do the same.
If you want to help, then find a way to push the student in the right direction. But posting a complete solution does far more harm than good.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Linear Algebra finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by