Warning: Error updating FunctionLine using fplot

15 visualizzazioni (ultimi 30 giorni)
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);

Risposta accettata

Jai Harnas
Jai Harnas il 23 Mar 2021
Modificato: Jai Harnas il 23 Mar 2021
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 Commenti
Walter Roberson
Walter Roberson il 23 Mar 2021
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 il 24 Mar 2021
That makes sense, Thank you!

Accedi per commentare.

Più risposte (1)

Walter Roberson
Walter Roberson il 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 Commento
Jai Harnas
Jai Harnas il 23 Mar 2021
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?

Accedi per commentare.

Categorie

Scopri di più su Programming in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by