Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: How to integrate discrete function?
Replies: 2   Last Post: Dec 5, 2012 3:09 PM

 Messages: [ Previous | Next ]
 Sanaa Posts: 171 Registered: 3/20/12
Re: How to integrate discrete function?
Posted: Dec 5, 2012 3:09 PM

"pietro " <bracardi82@email.it> wrote in message <k9ll5c$nfg$1@newscl01ah.mathworks.com>...
> "Sanaa" wrote in message <k9lhqk$ai2$1@newscl01ah.mathworks.com>...
> > Hello,
> > I want to integrate the discrete function a*x_n*(1-x_n) from nr to t (take r=0.005)
> > where a:0:0.001:4 and n=0,1,2,3,...., and t\in[nr,(n+1) r]
> > Thanks a lot.

>
> use cumtrapz

I have tried the following

%%%%%%%%%%%%%%%%%%%%
% define the vector of colors, to plot the dat aof reach value of r in
% different color
color_vec = ['b'];
r=0.05;
for rho = 0: 0.001:5
r_vec=r;
% do a loop of values of r
for j = 1 : size(r_vec,2)
% define delay
r = r_vec(j);
% define coefficient rho
%rho = 0.5;
% define the number of deiscrete times in interval [k*r, (k+1)*r]
n = 50;
% define the nimber of iterations k = 1,.....,Nit
Nit = 300;
% define the initial vector which is a vector of size n
x0 = 0.3*ones(1,n);
% define vectors x_next and x_previous
x_next = zeros(1,n); %x_(n+1)
x_previous = zeros(1,n); %x_n

time = zeros(1,n);

% initialize x_previous
x_previous = x0;
time = zeros(1,n);
%x_next = x_previous;
time = linspace(0,r,n);

hold on
for i = 1:Nit
time = linspace(i*r,(i+1)*r,Nit);
y_next=rho.*x_previous.*(1-x_previous);
x_next = x_previous+ cumtrapz(y_next);
x_previous = x_next;
end
end
plot(rho,x_next(1),'.', 'Color', char(color_vec(j)))
end

When I execute the results, I found out that x and y go to starting from the second value for each? What's wrong in my code?
Moreover, I want to integrate ''y'' from nr to time; how can I do this using cumtrapz?

Date Subject Author
12/4/12 Sanaa
12/4/12 pietro
12/5/12 Sanaa