if statement with and or

3 Ansichten (letzte 30 Tage)
Marco Lepidi
Marco Lepidi am 28 Dez. 2021
Kommentiert: Marco Lepidi am 28 Dez. 2021
Hi sorry, i want to create a code to know if a generic matrix A is positive definite. On my version of matlab (2016) when i write the second & the code gives me an error saying that "Matrix dimensions must agree". Can you help me?
A=[13/4 1/2 0; 1/2 17/4 1/2; 0 1/2 21/4]
A = 3×3
3.2500 0.5000 0 0.5000 4.2500 0.5000 0 0.5000 5.2500
[n,m]=size(A);
D_A=diag(A);
M_A=A-diag(D_A);
if n==m & A==A' & (abs(D_A)>sum(abs(M_A),2) | abs((D_A)')>sum(abs(M_A),1)) & diag(A)>0
disp 'A è DEFINITA POSITIVA'
end
A è DEFINITA POSITIVA
  12 Kommentare
Voss
Voss am 28 Dez. 2021
isequal is for comparing arrays (especially non-scalar arrays). all is for checking a condition on elements of an array.
Marco Lepidi
Marco Lepidi am 28 Dez. 2021
@Benjamin thank you very much

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Performance and Memory finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by