English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I am not too bad at programming, but this little annoyance in MATLAB is driving me crazy, and I need to finish this off asap (my advisor is leaving for holiday in 2 days!).

I am interested in summing up the resultant amplitude from a population of oscillators, each of which is a solution of the van der Pol equation with parameter u>0 with the following property: the time periods of the ensemble are Gaussian-ly distributed with mean T and SD s.

I wish to use MATLAB to evaluate this sum. I can evaluate the v.d.P. solution in a function, can generate random normally distributed numbers using randn() but somehow the eventual summing up which involves an iterative call to the ODE function from a main fucntion is not giving me the sum correctly. I have tried making the sum a global variable too. I could have posted the code too, as evidence that I am not askng you to do my homewoek, but my advisor will not like that.

Please help!!

2007-05-27 10:42:57 · 2 answers · asked by Anonymous in Science & Mathematics Mathematics

2 answers

I'm not familiar with the van der Pol equation, and even less familiar with your problem, so I can only offer possibilities. But I think they're good ones. ;-)

For a start, much depends on whether you need to evaluate the solutions once only or repeatedly for each element in the ensemble. If once, you may be able to get away with assigning the time period randomly on the fly, but if you need to evaluate them repeatedly (perhaps to get values at many points) this won't work very well.

Also, remember the fundamental principle of MATLAB: Never iterate if you can use an array. Probably you can't use an array to do all your oscillators at once (though if you can, you definitely should!) - but I'll assume you can compute a whole vector of points for each oscillator in a single function call.

So with that in mind, for N oscillators and n data points per solution I'd propose something like

times = randn(1, N) * s + T;
sols = zeros(n, N);
xvals = (x0 : xstep : x1)';

for i = 1:N
sols(:, i) = van_der_pol(times(i), xvals);
end
sums = sum(sols, 2);

where van_der_pol should obviously be replaced by whatever you've called your M-file.

Bear in mind that it's about 4 years since I last used MATLAB and therefore the above code is untested, but it should be pretty close. Fortunately MathWorks have the MATLAB function reference available on the Web. ;-)

2007-05-27 20:44:17 · answer #1 · answered by Scarlet Manuka 7 · 0 0

I once had a problem kind of like this, and I think that what fixed it was defining the basic function in a separate m file. Not exactly sure, though. Let me know if it works.

2007-05-27 20:03:22 · answer #2 · answered by Paul D 3 · 1 0

fedest.com, questions and answers