How can I add rabdom variables to an ode

1 回表示 (過去 30 日間)
Bill
Bill 2014 年 2 月 4 日
回答済み: Bill 2014 年 2 月 4 日
So i have these two differential equations that I can solve but I want to add a noisy term to one of the variables, the options are to either have a random number between -1 and 1 or just a sin/cos term that varies between this, the code runs fine until i attempt to add this noise then it gets errors can anyone help i am just not sure how to add this noisy term
h=0.01;
ti=0;
tf=5;
N=floor(tf/h);
t=linspace(ti, tf, N);
b = 2;
a = 0.5;
x(1)=0.1;
y(1)=0.1;
noise=rand(-1,1);
for i=1:(N-1)
x_tmp = x(i)+h*a*x(i)*(8-x(i))*(x(i)*x(i)-16);
y_tmp = y(i)+h*(6+b^2) +h*noise;
x(i+1) = x(i)+h/2*(a*x(i)*(8-x(i))*(x(i)*x(i)-16))+a*x_tmp*(8-x_tmp)*(x_tmp*x_tmp-16);
y(i+1) = y(i)+h/2*(6+b*b+y_tmp);
end
  2 件のコメント
Mischa Kim
Mischa Kim 2014 年 2 月 4 日
Without having gone through your code, what makes you think that the code does not work "fine" anymore when adding noise?
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 2 月 4 日
Post your ode function

サインインしてコメントする。

回答 (2 件)

Paul
Paul 2014 年 2 月 4 日
編集済み: Paul 2014 年 2 月 4 日
rand gives a random value between 0 and 1. The arguments of rand are not the boundaries but the size (of the matrix) of the output. change
noise=rand(-1,1);
to:
noise = -1 + 2*rand(1)

Bill
Bill 2014 年 2 月 4 日
Thanks it runs now, but it doesn't seem to actually do anything i.e add noise, is it changing with iteration or is it because the amplitude h is so small that any effect is removed?

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by