Getting factorials to work in my equation
Mostrar comentarios más antiguos
Hello everyone,
I am having a problem with my code where I need to use a factorial due to the equation needing it in the denominator as I'm solving for a Fourier coefficient. I keep getting: Error using factorial (line 20) N must be an array of real non-negative integers.
Here is the code I'm using:
if true
clear all, close all, clc
format long
fc = 2E9 %center frequency
W0 = 1 %omega 0
Tao = 30E-3 %Tao
T = 0.1 %T
k = linspace(0, 10E12, 1000) %k
y = ((((-1).^k).*(k.*pi.*(fc+(k.*10)).*Tao).^2.*k)./factorial(2.*k+1))
x = sum(y)
Ck = W0*(Tao/T)*abs(x) %coefficient
figure(1)
plot(Ck,y)
% code
end
First of all I'm confused by the line 20 since there are not that many lines in my code, but I get this error right after "Error in PlottingFourierCoeff (line 8) y = ((((-1).^k).*(k.*pi.*(fc+(k.*10)).*Tao).^2.*k)./factorial(2.*k+1))" and that makes sense since that's where the factorial comes into play. My code may be a little rough because I started at at the end of the day yesterday and didn't get all the way through it since I knew I needed to figure out how to fix the factorial problem, but thank you for any help on this matter in advance!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Mathematics en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!