How to plot these equations ?
显示 更早的评论
Hello
I'm trying to plot these polynomials shown in the image, but I keep receiving errors and I'm not if my code is correct of not. Could you please help ?
regards

clear all
close all
clc
%%
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sampling period
L = 1024; % Length of signal
t = 2*(0:L-1)*T; % Time vector
x = 0;
c = 1+i;
P(1) = 1;
Q(1) = 1;
P(2) = P(1) + exp(i*(2^(0))*t)*Q(1);
Q(2) = P(1) - exp(i*(2^(0))*t)*Q(1);
P(3) = P(2) + exp(i*(2^(1))*t)*Q(2);
Q(3) = P(2) - exp(i*(2^(1))*t)*Q(2);
P(4) = P(3) + exp(i*(2^(2))*t)*Q(3);
Q(4) = P(3) - exp(i*(2^(2))*t)*Q(3);
for m=1:16
x = x +c*exp(i*2*pi*m*t).*P(m);
end
figure
subplot(2,2,1)
plot(t,x)
title('signal')
6 个评论
Image Analyst
2022-1-23
编辑:Image Analyst
2022-1-23
What is this "x" that you're overwriting on each iteration of the for loop? I thought you wanted to compute p and q, not x.
And MATLAB thinks i is a variable. So if you want to use it as a variable you need to use
i = sqrt(-1);
or else use a 1 in front of it: 1i
Matt J
2022-1-23
They don't look like polynomials to me. Also, they are complex-valued, so what does it mean to "plot" them? If you want to plot their absolute value, do plot(t,abs(x)).
Mohamed Ahmed
2022-1-23
Mohamed Ahmed
2022-1-23
Matt J
2022-1-23
That is correct. P(2) is a scalar location. It cannot hold a vector
Mohamed Ahmed
2022-1-23
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

