필터 지우기
필터 지우기

ode45 and euler not working for random signal

조회 수: 2 (최근 30일)
SEEmULATER
SEEmULATER 2020년 6월 5일
댓글: darova 2020년 6월 13일
When trying to simulate a first order system subject to a random input that changes value at fixed intervals, neither my ode45 nor euler integration attempts make sense to me. Neither of them follow the inut signal. Please help!
(This code reqs 2016b or later I think)
clc;clear;close all;format compact
w_filt = 10*2*pi; % first order filter
t = linspace(0,1,1000);
dt = t(2)-t(1);
inits = [0];
%% Try ODE 45
Eqns = @(t,s) eqns(t,s,dt,w_filt);
[t,x] = ode45(Eqns,t,inits);
for i = 1:length(t)
[dx(i,:),ext(i)] = Eqns(t(i),x(i));
end
in = ext;
du = dx;
u = x;
%% Try Euler
X = inits;
for i = 1:length(t)-1
dX(i) = w_filt*(in(i) - X(i));
X(i+1) = du(i)*dt + X(i);
end
dX(end+1) = 0;
%% Plots
figure(1);
title('ODE45');
plot(t,u,t,du,t,in)
legend('u','du','input')
figure(2);
title('Euler Integration')
plot(t,X,t,dX,t,in)
legend('u','du','input')
%% EOM
function [dx,ext] = eqns(t,x,dt,w_relax)
global randval
u = x;
in = randval;
if rem(t,100*dt) == 0 || t == 0
in = 0.1*pi/180*(2*rand-1);
randval = in;
end
du = w_relax*(in - u);
dx = du;
ext = in;
end

답변 (1개)

James Tursa
James Tursa 2020년 6월 5일
편집: James Tursa 2020년 6월 5일
You can't use random inputs with ode45( ). ode45( ) relies on the ability to call the derivative function at arbitrary times to control esimated errors. It may even call your derivative function in non-increasing times because of this. It needs the derivatives to be consistent in order for this to work. Having randomness in your derivative function makes the derivatives inconsistent from call to call. ode45( ) will either fail with an error message because it can't get consistent estimated error results, or worse it will give you a garbage answer. You need to use another method besides ode45( ) to solve your stochastic problem.
  댓글 수: 3
James Tursa
James Tursa 2020년 6월 5일
And ...? Are you saying that your Euler scheme is not working, or doesn't give the expected results?
SEEmULATER
SEEmULATER 2020년 6월 5일
it does not give the expected results

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by