Divide by zero with subs

3 visualizaciones (últimos 30 días)
Ke Lu
Ke Lu el 25 de Nov. de 2015
Comentada: Christopher Creutzig el 4 de Abr. de 2016
When I try to execute the code below it gives me the error "Error in MuPAD command: Division by zero. [_power]". The problem is because the vector w_vec has a zero at position 5001. I have tried many approaches: inline if (according to some article I found), function to test the vector values, index vector, and some others. The problem still occurs.
The only way I've found was to change the w_vec(5001) to 1 before the problematic line and then to zero right after. Although solving the problem, it seems very strange to do like that. Is there any other solution to this problem?
This code does not belong to me. I've found this code trying to understand how Fourier Transform works.
Thanks!!!
syms t w
tau = 1;
rect_sym = heaviside(t+tau/2)-heaviside(t-tau/2);
fourier_rect_sym = fourier(rect_sym);
t_vec = -3:0.01:3;
rect_t = subs(rect_sym, t, t_vec);
w_vec = -50:0.01:50;
fourier_rect_w = subs(fourier_rect_sym, w, w_vec);
  1 comentario
Christopher Creutzig
Christopher Creutzig el 4 de Abr. de 2016
Try using matlabFunction instead of subs:
syms t w
tau = 1;
rect_sym = heaviside(t+tau/2)-heaviside(t-tau/2);
fourier_rect_sym = fourier(rect_sym,t,w);
fourier_rect = matlabFunction(fourier_rect_sym);
t_vec = -3:0.01:3;
rect_t = fourier_rect(t_vec);
w_vec = -50:0.01:50;
fourier_rect_w = fourier_rect(w_vec);

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 25 de Nov. de 2015
fourier_rect_w = arrayfun(@(W) limit(fourier_rect_sym,w,W), w_vec);

Community Treasure Hunt

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

Start Hunting!

Translated by