I get a warning with ODE45 and the code runs but slowly and message constantly appears while running: arning: The value of local variables may have been changed to match the globals...
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Matthew Gill
le 4 Nov 2017
Commenté : Walter Roberson
le 4 Nov 2017
Please help! First time to post a question here.
Warning: The value of local variables may have been changed to match the globals. Future versions of
MATLAB will require that you declare a variable to be global before you use that variable.
I have tried using all global and passing all through function. Some work both ways and some don't.
%%%SCRIPT
global TD y0 xi T
inputsize=1559;
m=1;
k=1;
h=0.02;
numberTDs=5;
%Import data and zero time and acceleration matrices
data=importdata('EarthquakeData.xlsx');
[ii,jj]=size(data);
acc=zeros(1,inputsize);
%T=zeros(1,inputsize);
T=0:h:(inputsize-1)*h;
n=1;
for i=1:ii
for j=1:jj
acc(1,n)=data(i,j);
n=n+1;
if n>inputsize
break
end
end
end
y0=[0,0];
[t,Y]=ode45('goodfunction1',T,y0,[],acc);
%%%FUNCTION
function ydot=goodfunction1(t,y,T,acc)
global TD xi y0 T
a=interp1(T,acc,t);
y0=[0,0];
ydot=[y(2);-(4*3.14159*xi/TD)*y(2)-(2*3.14159/TD)^2*y(1)-a];
end
0 commentaires
Réponse acceptée
Walter Roberson
le 4 Nov 2017
inputsize=1559;
m=1;
k=1;
h=0.02;
numberTDs=5;
%Import data and zero time and acceleration matrices
data=importdata('EarthquakeData.xlsx');
[ii,jj]=size(data);
acc=zeros(1,inputsize);
%T=zeros(1,inputsize);
T=0:h:(inputsize-1)*h;
n=1;
for i=1:ii
for j=1:jj
acc(1,n)=data(i,j);
n=n+1;
if n>inputsize
break
end
end
end
y0 = [0,0];
C1 = (4*pi*xi/TD);
C2 = (2*pi/TD)^2;
[t, Y] = ode45( @(t,y) goodfunction1(t, y, acc, C1, C2), T, y0);
%%%FUNCTION
function ydot = goodfunction1(t, y, acc, C1, C2 )
a = interp1(T, acc, t);
ydot = [y(2); -C1*y(2) - C2*y(1) - a];
end
However... your use of interp1 to interpolate tells us that your equations are at best piecewise continuous. That is not good enough for any of the ode*() solvers. ode45() will probably detect the inconsistency in equations the first time a makes a non-linear change, and will spend a whole lot of time trying to narrow down the instability. This would be very slow if it works at all.
In any case in which your equation suddenly changes like this, you should be stopping the ode and starting again with another ode45 call using the boundary conditions returned by the previous one. ode45() cannot handle discontinuities in any derivative that it is working with (and probably not in two more beyond that.)
4 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!