I don't have the cumtrapz function with FreeMat. I looked at Octave
and it's command isn't the same as MATLAB's. I wrote my own that
seems to work up to three dimensions anyway. Here it is inline:
% CUMTRAPZ - Cumulative trapezoidal numerical integration
%
% Usage
%
% Z = cumtrapz(Y)
% Z = cumtrapz(X,Y)
% Z = cumtrapz(Y,dim)
% Z = cumtrapz(X,Y,dim)
%
% Description
%
% Z = cumtrapz(Y) computes an approximation of the cumulative integral
of Y via
% the trapezoidal method with unit spacing. To compute the integral
with other
% than unit spacing, multiply Z by the spacing increment. Input Y can
be complex.
%
% For vectors, cumtrapz(Y) is a vector containing the cumulative
integral of Y.
%
% For matrices, cumtrapz(Y) is a matrix the same size as Y with the
cumulative
% integral over each column.
%
% For multidimensional arrays, cumtrapz(Y) works across the first
% nonsingleton dimension.
%
% Z = cumtrapz(X,Y) computes the cumulative integral of Y with respect
to X
% using trapezoidal integration. X and Y must be vectors of the same
length,
% or X must be a column vector and Y an array whose first nonsingleton
dimension
% is length(X). cumtrapz operates across this dimension. Inputs X and
Y can be
% complex.
%
% If X is a column vector and Y an array whose first nonsingleton
dimension
% is length(X), cumtrapz(X,Y) operates across this dimension.
%
% Z = cumtrapz(X,Y,dim) or cumtrapz(Y,dim) integrates across the
dimension of
% Y specified by scalar dim. The length of X must be the same as
size(Y,dim).
%
% Licensed under the GPL
% Copyright (C) 2010 Jonathan Weaver <jonw...@netscape.net>
function [A] = cumtrapz(x,y,dim)
% This program is free software; you can redistribute it and/or modify
it under
% the terms of the GNU General Public License as published by the Free
Software
% Foundation; either version 2 of the License, or (at your option) any
later
% version.
%
% This program is distributed in the hope that it will be useful, but
WITHOUT
% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS
% FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more
% details.
%
% You should have received a copy of the GNU General Public License
along with
% this program; if not, write to the Free Software Foundation, Inc.,
% 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
if (nargin 1) %cumtrapz(y)
[y, dim] = shiftdim(x);
x = 1:size(y,1);
elseif(nargin 2) %cumtrapz(x,y) or cumtrapz(y,dim)
if(isscalar(y)) %cumtrapz(y,dim)
dim = y - 1;
y = shiftdim(x, dim);
x = 1:size(y,1);
else %cumtrapz(x,y);
[y, dim] = shiftdim(y);
if(length(x) ~= size(y,1))
error('The length of x must be equal to the length of
the first non-singleton dimension of y');
end
end
elseif(nargin 3) %cumtrapz(x,y,dim)
dim = dim - 1;
y = shiftdim(y,dim);
if(length(x) ~= size(y,1))
error('The length of x must be equal to the size(Y,dim)');
end
else
error('Invalid number of arguments');
end
n = size(y);
m = n(2:end);
a = [zeros([1 m]); (y(1:(n(1)-1),:,:,:,:,:)+y(2:n(1),:,:,:,:,:))/
2.*repmat(diff(x)', [1 m])];
A = shiftdim(cumsum(a),length(n) - dim);
end
> > .
and it's command isn't the same as MATLAB's. I wrote my own that
seems to work up to three dimensions anyway. Here it is inline:
% CUMTRAPZ - Cumulative trapezoidal numerical integration
%
% Usage
%
% Z = cumtrapz(Y)
% Z = cumtrapz(X,Y)
% Z = cumtrapz(Y,dim)
% Z = cumtrapz(X,Y,dim)
%
% Description
%
% Z = cumtrapz(Y) computes an approximation of the cumulative integral
of Y via
% the trapezoidal method with unit spacing. To compute the integral
with other
% than unit spacing, multiply Z by the spacing increment. Input Y can
be complex.
%
% For vectors, cumtrapz(Y) is a vector containing the cumulative
integral of Y.
%
% For matrices, cumtrapz(Y) is a matrix the same size as Y with the
cumulative
% integral over each column.
%
% For multidimensional arrays, cumtrapz(Y) works across the first
% nonsingleton dimension.
%
% Z = cumtrapz(X,Y) computes the cumulative integral of Y with respect
to X
% using trapezoidal integration. X and Y must be vectors of the same
length,
% or X must be a column vector and Y an array whose first nonsingleton
dimension
% is length(X). cumtrapz operates across this dimension. Inputs X and
Y can be
% complex.
%
% If X is a column vector and Y an array whose first nonsingleton
dimension
% is length(X), cumtrapz(X,Y) operates across this dimension.
%
% Z = cumtrapz(X,Y,dim) or cumtrapz(Y,dim) integrates across the
dimension of
% Y specified by scalar dim. The length of X must be the same as
size(Y,dim).
%
% Licensed under the GPL
% Copyright (C) 2010 Jonathan Weaver <jonw...@netscape.net>
function [A] = cumtrapz(x,y,dim)
% This program is free software; you can redistribute it and/or modify
it under
% the terms of the GNU General Public License as published by the Free
Software
% Foundation; either version 2 of the License, or (at your option) any
later
% version.
%
% This program is distributed in the hope that it will be useful, but
WITHOUT
% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS
% FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more
% details.
%
% You should have received a copy of the GNU General Public License
along with
% this program; if not, write to the Free Software Foundation, Inc.,
% 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
if (nargin 1) %cumtrapz(y)
[y, dim] = shiftdim(x);
x = 1:size(y,1);
elseif(nargin 2) %cumtrapz(x,y) or cumtrapz(y,dim)
if(isscalar(y)) %cumtrapz(y,dim)
dim = y - 1;
y = shiftdim(x, dim);
x = 1:size(y,1);
else %cumtrapz(x,y);
[y, dim] = shiftdim(y);
if(length(x) ~= size(y,1))
error('The length of x must be equal to the length of
the first non-singleton dimension of y');
end
end
elseif(nargin 3) %cumtrapz(x,y,dim)
dim = dim - 1;
y = shiftdim(y,dim);
if(length(x) ~= size(y,1))
error('The length of x must be equal to the size(Y,dim)');
end
else
error('Invalid number of arguments');
end
n = size(y);
m = n(2:end);
a = [zeros([1 m]); (y(1:(n(1)-1),:,:,:,:,:)+y(2:n(1),:,:,:,:,:))/
2.*repmat(diff(x)', [1 m])];
A = shiftdim(cumsum(a),length(n) - dim);
end
On Nov 16, 6:02 am, Timothy Cyders <t.cyd...@gmail.com> wrote:
> If a numerical solution will suit you (indefinite integrals need not apply),
> you might look at the cumtrapz() function. Example: if you want to take the
> integral of y = x^2+4*x from 0 to 10,
>
> x = 0:0.01:10; % better resolution will give you more precise results
> y = x.^2+4*x;
> integral = cumtrapz(x,y) % gives a vector of values for the definite
> integral from x(1) to x(n). The last value integral(length(integral)) is the
> overall definite integral.
>
> TJ
>
> On Tue, Nov 16, 2010 at 2:38 AM, Eugene <gene...@gmail.com> wrote:> > fre...@googlegroups.com<freemat%2Bunsubscribe@googlegroups.com>
> > FreeMat does not support symbolic operations (yet). You need symbolic
> > algebra software, e.g. Maxima (http://maxima.sourceforge.net/).
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > 'freemat' group.
> > To post to this group, send email to fre...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > .
Free Math Games
Freemathworksheets.net
FreeMat is a free environment for rapid engineering and scientific prototyping and data processing. It is similar to commercial systems such as MATLAB from Mathworks, and IDL from Research Systems, but is Open Source. FreeMat is available under the GPL license. News Updated News - 2013-06-31 - FreeMat 4.2 - 32 bit binary for Windows.
Freematures.net
- FreeMat is a comprehensive piece of software designed to work as a development environment, similar to MATLAB or IDL, yet with none of the entailed costs. The installation requires prior knowledge.
- In many ways FreeMat, MatLab, SciLab, or Octave has succeeded Fortran as the most popular programming language in the science and engineering communities. MATLAB is a commercial software and is available from www.mathworks.com. FreeMat is an open source software that is similar to MatLab. FreeMat can be downloaded by clicking this link.