How can I combine these two codes?
Show older comments
I am studying the book "Contemporary Communication Systems using MATLAB", and I am stuck on question 1.4. I should use the m-file fseries.m:
function xx=fseries(funfcn,a,b,n,tol,p1,p2,p3)
args0=[];
for nn=1:nargin-5
args0=[args0,',p',int2str(nn)];
end
args=[args0,')'];
t=b-a;
xx(1)=eval(['1/(',num2str(t),').*quad(funfcn,a,b,tol,[]',args]) ;
for i=1:n
new_fun = 'exp_fnct' ;
args=[',', num2str(i), ',', num2str(t), args0, ')' ] ;
xx(i+1)=eval(['1/(',num2str(t),').*quad(new_fun,a,b,tol,[],funfcn',args]);
end
but after debugging this error appears:
Error in ==> fseries at 19
t=b-a;
as I understood the [a,b] is an interval and the signal in the interval [a,b] is given in an another m.file:
n=[-20:1:20];
x=abs(sinc(n/2));
stem(n,x);
so, how can I combine these two and solve the question?
Thanx
Answers (1)
Jan
on 23 Aug 2012
Not an answer!
At first omit the strange EVAL junk:
function xx=fseries(funfcn,a,b,n,tol,varargin)
t=b-a;
xx(1) = 1/t .* quad(funfcn,a,b,tol,[],varargin{:});
for i=1:n
xx(i+1) = 1/t .* quad(@exp_fnct, a, b, tol, [], funfcn, i, t, varargin{:});
end
This looks easier, doesn't it?
Categories
Find more on Signal Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!