Warning: Error updating FunctionLine using fplot
Afficher commentaires plus anciens
Hi all, Wondering why i am getting the warning: error updating FunctionLine warning when trying to plot from a series addition, below is code attached which all works apart from the "fplot(s, [-pi,pi])"
Thanks in advance!
clear
syms k
w=2; %angular frequency
T=(2*pi)/w; %working out the period
f1=@(t)(4+t)/2; %f(t)
f2=@(t) (2-t).*cos(2*t); %f(t)
hold on %plotting both functions within their intervals
fplot(f1,[-pi,0]);
fplot(f2,[0,pi]);
%labelling the axis
xlabel('Time (s)')
ylabel('Cosine Values')
%evaluating C0
c0=(1/T)*integral(f1,-T/2,0)+(1/T)*integral(f2,0,T/2);
%evaluating Cn values up to n=10 from n=1
for n = 1:10
f3=@(t) ((4+t)/2).*exp(-1j*n*w*t);
f4=@(t) ((2-t).*cos(2*t)).*exp(-1j*n*w*t);
c(n)=(1/T)*integral(f3,-T/2,0)+(1/T)*integral(f4,0,T/2);
n=+1;
end
%series addition for k=-10:10
s=@(t) symsum(c(k).*exp(1j*k*w*t),-10,10);
fplot(s,[-pi,pi])
%evaluating the average energy of the signal
f5=@(t) abs((4+t)/2).^2;
f6=@(t) abs((2-t).*cos(2*t)).^2;
E=(1/T)*integral(f5,-T/2,0)+(1/T)*integral(f6,0,T/2);
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 23 Mar 2021
s=@(t) symsum(c(k).*exp(1j*k*w*t),-10,10);
c is an array. k is symbolic variable . You can never use a symbolic variable as an index.
Make t symbolic and k=-10:10 and take a definite sum. Then use matlabFunction to convert into a numeric function.
You will then encounter the problem that you are trying to take c(-10) but c is a vector.
1 commentaire
Jai Harnas
le 23 Mar 2021
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
