Ode45 would not converge with the following statement

1 Ansicht (letzte 30 Tage)
Hi Everyone,
I have been struggling with ode45 for over a week and there is a weird convergence problem. So in my ode I have the following lines
B = kron(A, eye(3)); % size(A)=[n n]
C = B*y; % size(y)=[3*n 1]
and then C will be used in later calculations
And the ode kept returning NAN, I set A = zeros(n,n) and the problem still persists
However, if I set C=zeros(3*n,1) the ode converges well.
To my understanding, by setting A = zeros(n,n) and running the above lines, no matter what value y is C will be equal to zeros(3*n,1), then why would it affect the convergence of the ode? Anyone familiar with the problem here?
Thanks a lot!
  1 Kommentar
Walter Roberson
Walter Roberson am 14 Jul. 2018
When you set A to zeros(n,n), then what shows up for class(C) and nnz(C) ?
Is it possible your y is not class double ?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Carlos Felipe Rengifo
Carlos Felipe Rengifo am 14 Jul. 2018
Hi, I guess the "y" vector contains a NaN, and as a consequence "C" contains also NaNs. This happen even if B is equal to zero (0 * nan = nan). You can verify this by adding the following sentence to your code:
if any(isnan(y))
disp('There is a nan in the vector y' );
end
  2 Kommentare
Ying Liu
Ying Liu am 16 Jul. 2018
Hi Carlos,
Yes, it is exactly the reason you said, while iterating over time and space y vector contains NaN. Thanks!
Walter Roberson
Walter Roberson am 16 Jul. 2018
Good catch, Carlos!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Identification finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by