initial import

This commit is contained in:
Dave Goodwin 2004-02-23 05:47:11 +00:00
parent a75e7f10be
commit ab71bf66c4
7 changed files with 101 additions and 0 deletions

View file

@ -0,0 +1,52 @@
function s = char(p)
% CHAR -
%
if strcmp(p.typ,'sum')
s = ['(' char(p.f1) ') + (' char(p.f2) ')'];
elseif strcmp(p.typ,'diff')
s = ['(' char(p.f1) ') - (' char(p.f2) ')'];
elseif strcmp(p.typ,'prod')
s = ['(' char(p.f1) ') * (' char(p.f2) ')'];
elseif strcmp(p.typ,'ratio')
s = ['(' char(p.f1) ') / (' char(p.f2) ')'];
elseif all(p.coeffs == 0)
s = '0';
else
if strcmp(p.typ,'polynomial')
d = length(p.coeffs) - 1;
s = [];
nn = 0;
for b = p.coeffs;
cc(d+1-nn) = b;
nn = nn + 1;
end
for a = cc;
if a ~= 0;
if ~isempty(s)
if a > 0
s = [s ' + '];
else
s = [s ' - '];
a = -a;
end
end
if a ~= 1 | d == 0
s = [s num2str(a)];
if d > 0
s = [s '*'];
end
end
if d >= 2
s = [s 'x^' int2str(d)];
elseif d == 1
s = [s 'x'];
end
end
d = d - 1;
end
else
print 'char not yet implemented';
end
end

View file

@ -0,0 +1,9 @@
function d = display(a)
% DISPLAY -
%
disp(' ');
disp([inputname(1),' = '])
disp(' ');
disp([' ' char(a)])
disp(' ');

View file

@ -0,0 +1,6 @@
function r = plus(a, b)
% PLUS -
%
r = Func('sum',a,b);

View file

@ -0,0 +1,13 @@
function v = funcmethods(n, job, a, b, c, d)
%
if nargin == 2
v = ctmethods(110, n, job);
elseif nargin == 3
v = ctmethods(110, n, job, a);
elseif nargin == 4
v = ctmethods(110, n, job, a, b);
elseif nargin == 5
v = ctmethods(110, n, job, a, b, c);
elseif nargin == 6
v = ctmethods(110, n, job, a, b, c, d);
end

View file

@ -0,0 +1,5 @@
function r = rdivide(a,b)
% RDIVIDE -
%
r = Func('ratio',a,b);

View file

@ -0,0 +1,11 @@
function b = subsref(a,s)
% SUBSREF
switch s.type
case '()'
ind = s.subs{:};
for k = 1:length(ind)
b(k) = funcmethods(2,a.index,ind(k))
end
otherwise
error('Specify value for x as p(x)')
end

View file

@ -0,0 +1,5 @@
function r = times(a,b)
% TIMES -
%
r = Func('prod',a,b);