How to introduce a random variable in ode45?

Hi to all, I am quite new in Matlab, thanks in advance for your help. I am trying to solve a system of differential equations similar to:
r1'(t)=f(r1,r2,t)+g(r1,r2,t)*z(t);
r2'(t)=j(r1,r2,t)+h(r1,r2,t)*z(t);
I am using ode45 by defining a function file with f, g, j and h. Now my problem is to introduce z(t) as a random number for a normal distribution. This random numbers can be obtained using normrnd(mu,sigma), however, I need my program to take on different random number for each time but use the same at each time for r1' and r2'. Thanks a lot for your help.

 採用された回答

Paul
Paul 2014 年 3 月 2 日
編集済み: Paul 2014 年 3 月 2 日

0 投票

Add
rng('shuffle')
before calling normrnd.

3 件のコメント

J Alonso
J Alonso 2014 年 3 月 2 日
Thanks again, can you a little bit more explicit:
I have the file f.m
function z=f(t,r)
z=zeros(2,1);
z(1)=f(r1,r2,t)+g(r1,r2,t)*normrnd(mu,sigma); z(2)=j(r1,r2,t)+h(r1,r2,t)*normrnd(mu,sigma);
Thanks for your time
Paul
Paul 2014 年 3 月 2 日
編集済み: Paul 2014 年 3 月 2 日
function z=f(t,r)
z=zeros(2,1);
rng('shuffle')
z(1)=f(r1,r2,t)+g(r1,r2,t)*normrnd(mu,sigma); z(2)=j(r1,r2,t)+h(r1,r2,t)*normrnd(mu,sigma);
J Alonso
J Alonso 2014 年 3 月 2 日
Thanks, now it works.

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

その他の回答 (0 件)

カテゴリ

質問済み:

2014 年 3 月 2 日

コメント済み:

2014 年 3 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by