Warning: Error updating FunctionLine using fplot

조회 수: 19 (최근 30일)
Jai Harnas
Jai Harnas 2021년 3월 23일
댓글: Jai Harnas 2021년 3월 24일
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])
Jai Harnas
Jai Harnas 2021년 3월 24일
That makes sense, Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (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