On 110303 05:28 PM, Paulo Silva wrote:
> "Animesh Pandey" wrote in message <ikopov$qoj$1@fred.mathworks.com>...
>> syms an bn a0;
>> syms t n;
>> syms x;
>> T = input('Enter the Time Period');
>> N = input('Enter the number of terms');
>> x = input('Enter the function');
>> f = @(t) x;
>>
>> an = int(f(t).*cos(n*pi*t/T),t,T,T)*(1/T); bn =
>> int(f(t).*sin(n*pi*t/T),t,T,T)*(1/T); a0 = int(f(t),t,T,T)*(1/T); y = a0;
f(t) is x, and n is symbolic, so the integral of "an" will be an expression in
two variables; likewise for "bn"
>>
>> pretty(a0);
>> pretty(an);
>> pretty(bn);
>>
>>
>> for i=N:1:N;
>> y = y + subs(an, i) + subs(bn, i);
>> end
As "an" and "bn" have two variables, "x" and "n", which variable are you
expecting that subs() will substitute the value of "i" in to? The answer is
that it will use "the default symbolic variable", symvar(an,1), which is "the
symbolic variable whose name is alphabetically closest to 'x'". As you have an
'x', it will substitute in for that, leaving "n" unchanged. Is that what you
want, or do you want to be substituting in for "n" ?
Warning: if you leave it substituting for x, then since x appears as a plain
multiplier term in the integral and you are running from T to +T, each
negative multiple is going to cancel out a positive multiple, leaving the
result as 0.
