Warning: Error updating FunctionLine using fplot

14 次查看(过去 30 天)
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);

采纳的回答

Jai Harnas
Jai Harnas 2021-3-23
编辑:Jai Harnas 2021-3-23
Manages to do what i said and got rid of the error, the function now plots and the notation is a bit messy, but everything works.
%turning values n=1:10 to conjugates for i=-1:-10
cc=conj(c);
%series addition for k=-10:10
k=1:10
s=@(t) c0+(sum(c(k).*exp(1j*k*w*t))+(sum(cc(k).*exp(1j*-1*k*w*t))));
fplot(s,[-pi,pi])
However, i still get the Warning: Function behaves unexpectedly on array inputs. and any advice on how to fix this to make it work properly would be appreciated. Thank you
  2 个评论
Walter Roberson
Walter Roberson 2021-3-23
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)
c0=(1/T)*integral(f1,-T/2,0)+(1/T)*integral(f2,0,T/2);
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)=(1/T)*integral(f3,-T/2,0)+(1/T)*integral(f4,0,T/2);
end
cc=conj(c);
%c and cc and k must be column vectors for the below to work properly. t
%will be received as a row vector.
k = (1:10).';
s=@(t) c0 + sum(c(k).*exp(1j.*k.*w.*t),1) + sum(cc(k).*exp(1j.*-1.*k.*w.*t),1);
fplot(s,[-pi,pi])

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2021-3-23
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 个评论
Jai Harnas
Jai Harnas 2021-3-23
Thank you that makes a lot of sense. Is there anyway that i can overcome this problem? Maybe a way to convert the 10 values for c from a+jb to a-jb and do two different definite sums that way whilst leaving k=0 out, as it is calculated seperately?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by